如果我PopupUtils.open()
在Component.onCompleted
任何项目的属性中使用该命令,它什么也不做,例如:
Rectangle {
id: rect
height: 600
width: height
Component.onCompleted: {
PopupUtils.open(dialog, rect)
}
Component {
id: dialog
Dialog {
id: dialogue
title: "Save file"
text: "Are you sure that you want to save this file?"
Button {
text: "cancel"
onClicked: PopupUtils.close(dialogue)
}
Button {
text: "overwrite previous version"
color: "orange"
onClicked: PopupUtils.close(dialogue)
}
Button {
text: "save a copy"
color: "orange"
onClicked: PopupUtils.close(dialogue)
}
}
}
如何在应用程序启动后正确显示弹出对话框?
答案1
PopupUtils.Open(dialog, id) 用于按钮。
因此,添加一个可见属性为 false 的按钮,并将该隐藏按钮的 id 传递给上面的“id”(当然没有引用)。
来源:
遇到了同样的问题:)
答案2
由于某种原因,它使用 来工作Timer
,即:
Rectangle {
id: rect
height: 600
width: height
Component.onCompleted: {
start_timer.start()
}
Timer {
id: start_timer
interval: 200;
onTriggered: PopupUtils.open(dialog, rect)
}
Component {
id: dialog
Dialog {
id: dialogue
title: "Save file"
text: "Are you sure that you want to save this file?"
Button {
text: "cancel"
onClicked: PopupUtils.close(dialogue)
}
Button {
text: "overwrite previous version"
color: "orange"
onClicked: PopupUtils.close(dialogue)
}
Button {
text: "save a copy"
color: "orange"
onClicked: PopupUtils.close(dialogue)
}
}
}