HusPopup 弹窗

January 28, 2026 · View on GitHub

← 返回主目录

← 返回本类别目录

HusPopup 弹窗

自带跟随主题切换的背景和阴影, 用来替代内置 Popup。


支持的代理:


支持的属性:

属性名类型默认值描述
animationEnabledboolHusTheme.animationEnabled是否开启动画
movableboolfalse是否可移动
resizableboolfalse是否可改变大小
minimumXintNumber.NaN可移动的最小X坐标(movable为true生效)
maximumXintNumber.NaN可移动的最大X坐标(movable为true生效)
minimumYintNumber.NaN可移动的最小Y坐标(movable为true生效)
maximumYintNumber.NaN可移动的最大Y坐标(movable为true生效)
minimumWidthint0可改变的最小宽度(resizable为true生效)
maximumWidthintNumber.NaN可改变的最小宽度(resizable为true生效)
minimumHeightint0可改变的最小高度(resizable为true生效)
maximumHeightintNumber.NaN可改变的最小高度(resizable为true生效)
colorShadowcolor-阴影颜色
colorBgcolor-背景颜色
radiusBgHusRadius-背景圆角半径

代码演示

示例 1

使用方法等同于 Popup

通过 movable 设置为可移动

通过 resizable 设置为可改变大小

import QtQuick
import QtQuick.Controls.Basic
import HuskarUI.Basic

Item {
    height: 50

    HusButton {
        text: (popup.opened ? qsTr('隐藏') : qsTr('显示'))
        type: HusButton.Type_Primary
        onClicked: {
            if (popup.opened)
                popup.close();
            else
                popup.open();
        }
    }

    HusPopup {
        id: popup
        x: (parent.width - width) * 0.5
        y: (parent.height - height) * 0.5
        width: 400
        height: 300
        parent: Overlay.overlay
        closePolicy: HusPopup.NoAutoClose
        movable: true
        resizable: true
        minimumX: 0
        maximumX: parent.width - width
        minimumY: 0
        maximumY: parent.height - height
        minimumWidth: 400
        minimumHeight: 300
        radiusBg.topLeft: 100
        radiusBg.bottomRight: 100
        contentItem: Item {
            HusCaptionButton {
                anchors.right: parent.right
                radiusBg.topRight: popup.radiusBg.topRight
                colorText: colorIcon
                iconSource: HusIcon.CloseOutlined
                onClicked: popup.close();
            }
        }
    }
}