Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How do you add a popup window in QML?



  • How do you create a pop up window in QML, such that a separate window pops up, similar to that of the Qt C++ MainWindow function?





  • @edorval Hi,
    follow below example,

    Window {
        id: rootWindow
        visible: true
        width: 600
        height: 800
        property color popupBackGroundColor: "#b44"
        property color popupTextCOlor: "#ffffff"
    
        
        Popup {
                id: popup
                property alias popMessage: message.text
    
                background: Rectangle {
                    implicitWidth: rootWindow.width
                    implicitHeight: 60
                    color: popupBackGroundColor
                }
                y: (rootWindow.height - 60)
                modal: true
                focus: true
                closePolicy: Popup.CloseOnPressOutside
                Text {
                    id: message
                    anchors.centerIn: parent
                    font.pointSize: 12
                    color: popupTextCOlor
                }
                onOpened: popupClose.start()
            }
    
            // Popup will be closed automatically in 2 seconds after its opened
            Timer {
                id: popupClose
                interval: 2000
                onTriggered: popup.close()
            }
    }
    

Log in to reply