Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-69777

QML Window with Qt::Popup flag not behaving correctly (mouse not grabbed)



    • Type: Bug
    • Status: Reported
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.10.1
    • Fix Version/s: None
    • Labels:
    • Platform/s:


      When creating a sub-window in Qt Quick with the Qt::Popup flag set, it does not close when the user clicks on a point outside the window. 

      An equivalent implementation in Qt Widgets works correctly - the popup behaves exactly like a typical right-click context menu and disappears if the user clicks on any point of the screen which is not in the popup, no matter if the click was in the parent window or in a different application or even the desktop.

      Possibly, QQuickItem::grabMouse() is not called correctly?!

      See the following code snippets to understand the issue (tested on Linux X11).


      Qt Quick example:

      The popup won't disappear if the user clicks outside it. A kind of workaround is to listen to the onActiveChanged event and close the popup if the window lost its active state. However, this covers only the case when the user clicks on a different window. If you click on the parent window, the popup won't close.

      import QtQuick 2.2
      import QtQuick.Window 2.1
      Window {
          id: mainWindow
          width: 200
          height: 200
          Window {
              id: dropdown
              y: mainWindow.y + 50
              visible: true
              x: mainWindow.x + 50
              height: 200
              width: 200
              flags: Qt.Popup
              color: 'green'
              Text {
                  text: "I should disappear when you click anywhere outside me"
                  wrapMode: Text.WrapAnywhere
                  anchors.left: parent.left
                  anchors.right: parent.right
                  anchors.margins: 5
                  color: "white"


      Qt Widgets example:
      The popup is closed when the user clicks on any point of the screen which is not inside the popup (this is how it should be in Qt Quick as well).

      #include <QWindow>
      #include <QApplication>
      #include <QMainWindow>
      int main(int argc, char **argv)
        QApplication app(argc, argv);
        QMainWindow qWin;
        qWin.setFixedSize(640, 400);
        QWidget qPopup(&qWin, Qt::Popup);
        qPopup.setFixedSize(320, 200);
        return app.exec();


          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.



              qt.team.quick.subscriptions Qt Quick and Widgets Team
              syncu syncu
              0 Vote for this issue
              7 Start watching this issue



                  Gerrit Reviews

                  There are no open Gerrit changes