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

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

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.10.1
    • None
    • Linux/X11

    Description

      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);
        qWin.show();
      
        QWidget qPopup(&qWin, Qt::Popup);
      
        qPopup.setFixedSize(320, 200);
      
        qPopup.show();
      
      
        return app.exec();
      }
      
      

      Attachments

        Issue Links

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

          Activity

            People

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

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes