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

QML: mouse events filter

XMLWordPrintable

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

      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"

        1. filter2.zip
          7 kB
        2. qtbug38950.zip
          4 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

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

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes