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. Detect mouse click outside the modal window
QtWS25 Last Chance

Detect mouse click outside the modal window

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlmodal dialogpopup
2 Posts 1 Posters 2.6k Views
  • 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.
  • J Offline
    J Offline
    jimcad
    wrote on 6 Nov 2015, 22:11 last edited by jimcad 11 Oct 2015, 07:09
    #1

    I have modal dialog where is popup window. Popup is closed when mouse is clicked outside of popup in modal window. But I'd like to close popup also when is clicked anywhere outside the popup. How this can be done?

    import QtQuick 2.3
    import QtQuick.Controls 1.2
    import QtQuick.Window 2.1
    
    ApplicationWindow {
        visible: true
        width: 640
        height: 480
    
        Button {
            text: "Open modal window"
            anchors.centerIn: parent
            onClicked: { modalWindow.show() }
        }
    
        Window {
            id: modalWindow
            width: 300
            height: 400
            modality: Qt.ApplicationModal
            Rectangle {
                anchors.fill: parent
                border.width: 1
                MouseArea {
                    anchors.fill: parent
                    onClicked: {
                        popupWindow.show()
                    }
                }
                Button {
                    anchors.top: parent.top
                    anchors.right: parent.right
                    text: "Close"
                    onClicked: modalWindow.close()
                }
            }     
    
            Window {
                id: popupWindow
                flags: Qt.Popup
                width: 100
                height: 100
                x: Screen.width / 2
                y: Screen.height / 2
                Rectangle {
                    anchors.fill: parent
                    color: "green"
                }
            }       
        }
    }
    
    1 Reply Last reply
    0
    • J Offline
      J Offline
      jimcad
      wrote on 7 Nov 2015, 20:15 last edited by
      #2

      A small clarification. Popup window should work the same way as menu or combobox, so it should be closed when you click anywhere outside popup.

      1 Reply Last reply
      0

      2/2

      7 Nov 2015, 20:15

      • Login

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