属性
activeFocus : bool
anchors.centerIn : Object
availableHeight : real
availableWidth : real
background : Item
bottomInset : real
bottomMargin : real
bottomPadding : real
clip : bool
closePolicy : enumeration 关闭弹窗的方式
contentChildren : list<Item>
contentData : list<Object>
contentHeight : real
内容填充
contentItem : Item
contentWidth : real
dim : bool 非模态状态下对话框外区域背景色是否需要设置,模态的时候其他区域是深色的(可通过Overlay对弹窗外的区域进行设置)
enabled : bool
打开时转变的效果
enter : Transition
enter: Transition {
NumberAnimation {
property: "opacity";
from: 0.0;
to: 1.0
duration: 1000
}
}
关闭时的转变效果
exit : Transition
enter: Transition {
NumberAnimation {
property: "opacity";
from: 0.0;
to: 1.0
duration: 1000
}
}
focus : bool
font : font
height : real
horizontalPadding : real
implicitBackgroundHeight : real
implicitBackgroundWidth : real
implicitContentHeight : real
implicitContentWidth : real
implicitHeight : real
implicitWidth : real
leftInset : real
leftMargin : real
leftPadding : real
locale : Locale
margins : real
mirrored : bool
modal : bool 模态true后不可操作其他窗口,只有关闭窗口后才可操作其他窗口,模态时Popup.NoAutoClose慎用
opacity : real
opened : bool
padding : real
palette : palette
parent : Item
rightInset : real
rightMargin : real
rightPadding : real
scale : real
spacing : real
topInset : real
topMargin : real
topPadding : real
transformOrigin : enumeration
verticalPadding : real
visible : bool // 一个控件内套Popup 不会因为父控件是不可见的而子控件也不可见
width : real
x : real
y : real
z : real //popup作为一个弹窗,会覆盖其他类型的控件,该参数只是有效于相同类型的popup类弹窗
可见性
Rectangle{
width: 200
height: 200
color: "red"
visible: false
Popup{
width: 100
height: 60
visible: true
}
}
-》
z轴顺序
Popup 将其他类型的控件都进行遮盖,不管其z顺序,popup的z只是在不同得popup对象之间有效果
Rectangle{
width: 200
height: 200
color: "red"
visible: true
z:1
}
Rectangle{
width: 200
height: 200
x: 100
color: "blue"
visible: true
}
默认后声明的控件z更大
Popup{
width: 200
height: 200
visible: true
background: Rectangle{
color: "black"
}
}
Popup{
width: 200
height: 200
x: 100
visible: true
background: Rectangle{
color: "red"
}
z: 1
}
关闭弹窗
Popup{
id: popup
x:100
y: 100
width: 200
height: 300
visible: true
closePolicy: Popup.NoAutoClose //设置不能自动关闭弹框,只能手动调用接口关闭
}
/**
默认点击esc 和 谈窗外空白区域可关闭,Popup.CloseOnEscape | Popup.CloseOnPressOutside
Popup.NoAutoClose
The popup will only close when manually instructed to do so.
Popup.CloseOnPressOutside
The popup will close when the mouse is pressed outside of it.
Popup.CloseOnPressOutsideParent
The popup will close when the mouse is pressed outside of its parent.
Popup.CloseOnReleaseOutside
The popup will close when the mouse is released outside of it.
Popup.CloseOnReleaseOutsideParent
The popup will close when the mouse is released outside of its parent.
Popup.CloseOnEscape
The popup will close when the escape key is pressed while the popup has active focus.
*/
自定义弹窗内容
Popup{
id: popup
x:100
y: 100
width: 500
height: 300
visible: true
// closePolicy: Popup.NoAutoClose //设置不能自动关闭弹框,只能手动调用接口关闭
closePolicy: Popup.CloseOnEscape
modal: true
// dim:true
enter: Transition {
NumberAnimation {
property: "opacity";
from: 0.0;
to: 1.0
duration: 1000
}
}
exit: Transition {
NumberAnimation {
property: "opacity";
from: 1.0;
to: 0.0
duration: 1000
}
}
contentItem: Rectangle{
anchors.fill: parent
color: "gray"
Text{
id: txt
anchors.fill: parent
text: qsTr("message box area!!!!!")
font{
pixelSize: 26
}
wrapMode: Text.WordWrap //按字换行
}
Button{
anchors.bottom: parent.bottom
anchors.bottomMargin: 30
anchors.right: parent.right
anchors.rightMargin: 30
text: "cancel"
}
Button{
anchors.bottom: parent.bottom
anchors.bottomMargin: 30
anchors.left: parent.left
anchors.leftMargin: 30
text: "ok"
}
}
}
Overlay
属性
modal : Component 模态的对话框
modeless : Component 非模态的对话框
overlay : Overlay
非模态
Popup{
id: popup
x:100
y: 100
width: 400
height: 300
visible: true
// closePolicy: Popup.NoAutoClose //设置不能自动关闭弹框,只能手动调用接口关闭
closePolicy: Popup.CloseOnEscape
modal: false
dim:true
enter: Transition {
NumberAnimation {
property: "opacity";
from: 0.0;
to: 1.0
duration: 1000
}
}
exit: Transition {
NumberAnimation {
property: "opacity";
from: 1.0;
to: 0.0
duration: 1000
}
}
contentItem: Rectangle{
anchors.fill: parent
color: "gray"
Text{
id: txt
anchors.fill: parent
text: qsTr("message box area!!!!!")
font{
pixelSize: 26
}
wrapMode: Text.WordWrap //按字换行
}
Button{
anchors.bottom: parent.bottom
anchors.bottomMargin: 30
anchors.right: parent.right
anchors.rightMargin: 30
text: "cancel"
}
Button{
anchors.bottom: parent.bottom
anchors.bottomMargin: 30
anchors.left: parent.left
anchors.leftMargin: 30
text: "ok"
}
}
Overlay.modal: Rectangle{
anchors.fill: parent
color: "lightsteelblue"
}
Overlay.modeless: Rectangle{
anchors.fill: parent
color: "blue"
}
}
模态
modal: true
// dim:true
模态非弹窗区域点击
Popup{
id: popup
x:100
y: 100
width: 400
height: 300
visible: true
// closePolicy: Popup.NoAutoClose //设置不能自动关闭弹框,只能手动调用接口关闭
closePolicy: Popup.CloseOnEscape
modal: true
// dim:true
enter: Transition {
NumberAnimation {
property: "opacity";
from: 0.0;
to: 1.0
duration: 1000
}
}
exit: Transition {
NumberAnimation {
property: "opacity";
from: 1.0;
to: 0.0
duration: 1000
}
}
contentItem: Rectangle{
anchors.fill: parent
color: "gray"
Text{
id: txt
anchors.fill: parent
text: qsTr("message box area!!!!!")
font{
pixelSize: 26
}
wrapMode: Text.WordWrap //按字换行
}
Button{
anchors.bottom: parent.bottom
anchors.bottomMargin: 30
anchors.right: parent.right
anchors.rightMargin: 30
text: "cancel"
onClicked: {
console.log("cancel")
}
}
Button{
anchors.bottom: parent.bottom
anchors.bottomMargin: 30
anchors.left: parent.left
anchors.leftMargin: 30
text: "ok"
onClicked: {
console.log("ok")
}
}
}
Overlay.modal: Rectangle{
anchors.fill: parent
// color: "lightsteelblue"
color: "#33003322" //rgba
Popup{
width: parent.width
// height: parent.height
height: 90
visible: true
closePolicy: Popup.NoAutoClose
background: Rectangle{
color: "transparent" //透明色 使得下层的Popup可见
// color: "gray"
}
Button{
width: 50
height: 50
anchors.right: parent.right
onClicked: {
console.log("clicked")
}
}
}
}
Overlay.modeless: Rectangle{
anchors.fill: parent
// color: "blue" //英文字符
// color: "#202030" //rgb
color: "#20323022" //rgba
}
}