如何在應用程式啟動後顯示彈出對話框?

如何在應用程式啟動後顯示彈出對話框?

如果我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

由於某種原因,它使用 a 來工作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)
             }
         }
    }

相關內容