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

QML: mouse events filter

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.3.0 RC1
    • None

    Description

      If I create events filter using QObject with eventFilter defined as below:

      bool mouseEventsFilter::eventFilter(QObject *obj, QEvent *e) {
          static bool mousePressed = false;
          if(e->type() == QEvent::MouseMove && mousePressed) {
              QMouseEvent *event = static_cast<QMouseEvent*>(e);
              qDebug()<<"moved:"<<event->x();
          } else if(e->type() == QEvent::MouseButtonPress) {
              qDebug()<<"pressed";
              mousePressed = true;
          } else if(e->type() == QEvent::MouseButtonRelease) {
              qDebug()<<"released";
              mousePressed = false;
          }
      
          return QObject::eventFilter(obj, e);
      }
      

      and fill main.qml file with:

      import QtQuick 2.2
      import QtQuick.Window 2.1
      
      Window {
          visible: true
          width: 360
          height: 360
      
          MouseArea {
              anchors.fill: parent
          }
      
          Text {
              text: qsTr("Hello World")
              anchors.centerIn: parent
          }
      }
      

      then after single-click on Windows OS I can see:

      pressed
      pressed
      released
      released

      Of course I can use mousePressed variable to avoid this situation by taking only first event of QEvent::MouseButtonPress/QEvent::MouseButtonRelease. But with move events it won't be so easy to determine which one needs to be handled or refused. They provide different mouseX/mouseY values depended (probably) on which Item can be found under mouse currently. The problem disappears after removing MouseArea from QML

      On Android device similar code can gives me even 3 different entries after only one screen touch.

      With previous Qt versions it behaves "normally"

      Attachments

        1. qtbug38950.zip
          4 kB
          Friedemann Kleint
        2. filter2.zip
          7 kB
          Krzysztof

        Issue Links

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

          Activity

            People

              aalpert Alan Alpert
              krzysztoff7 Krzysztof
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes