Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Window with Qt.Popup not closed
Forum Updated to NodeBB v4.3 + New Features

Window with Qt.Popup not closed

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I'm trying to create a popup window from within ApplicationWindow. When show() is called on the popup, it is shown, but when I click somewhere on my Desktop or the ApplicationWindow or anywhere else, the popup isn't closed automatically. However, it can be closed by explicitly calling its close() function.

    Doesn't work for me on Ubuntu 14.10 (64 bit, Unity) and Windows 7 (64 bit), both with original Nvidia graphics drivers.

    Looks like a bug in QtQuick.Window to me, or am I doing it wrong?

    @
    import QtQuick 2.4
    import QtQuick.Controls 1.3
    import QtQuick.Window 2.2

    ApplicationWindow {
    title: qsTr("Hello World")
    width: 640
    height: 480
    visible: true

    Item {
        anchors.fill: parent
        Button {
            id: button1
            text: "Click me"
            onClicked: mypopup.show()
        }
    }
    
    Window {
        id: mypopup
        flags: Qt.Popup
        Button {
            id: button2
            text: "Close"
            onClicked: mypopup.close()
        }
    }
    

    }
    @

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      Yes it is a bug. See "QTBUG-33481":https://bugreports.qt.io/browse/QTBUG-33481.

      157

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Thanks for the link, p3c0! I have found a way to hack around this. Unfortunately it involves using internal QtQuick features by importing "QtQuick.Controls.Private", but for the moment this is better than nothing :-)

        @
        import QtQuick 2.4
        import QtQuick.Controls 1.3
        import QtQuick.Window 2.2
        import QtQuick.Controls.Private 1.0

        ApplicationWindow {
        id: mainWindow
        title: qsTr("Hello World")
        width: 640
        height: 480
        visible: true

        property var popup: null
        
        function togglePopup() {
            if (popup == null) {
                popup = Qt.createQmlObject(
                            "import QtQuick 2.4
                             import QtQuick.Controls 1.3
                             import QtQuick.Window 2.2
                             import QtQuick.Controls.Private 1.0
                             PopupWindow {
                                id: mypopup
                                Rectangle {
                                    width: 100
                                    height: 100
                                    Button {
                                        id: button2
                                        anchors.centerIn: parent
                                        text: 'Close'
                                        onClicked: dismissPopup()
                                    }
                                }
                            }",
                            button1 )
                popup.onPopupDismissed.connect( afterPopupDismissed )
                popup.x = button1.x + button1.width
                popup.y = button1.y
                setTitle( "Popup created" )
                popup.show()
            } else {
                popup.destroy()
                popup = null
            }
        }
        
        function afterPopupDismissed() {
            popup.destroy()
            popup = null
            setTitle( "Popup dismissed" )
        }
        
        Button {
            id: button1
            text: "Click me"
            onClicked: togglePopup()
        }
        

        }
        @

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved