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

TapHandler does not produce MouseButtonRelease event for target item

    XMLWordPrintable

Details

    Description

      Code
      eventspy.h (This event filter is installed on the QGuiApplication)

      class EventSpy : public QObject
      {
          Q_OBJECT
      
      protected:
          bool eventFilter(QObject *watched, QEvent *event) override
          {
              auto result = QObject::eventFilter(watched, event);
      
              switch(event->type())
              {
              case QEvent::MouseButtonPress:
              case QEvent::MouseButtonRelease:
                  qDebug() << watched << event->type() << static_cast<QMouseEvent*>(event)->pos();
                  qDebug() << "\tResult:" << result;
                  break;
              default:
                  break;
              }
              return result;
          }
      };
      

       

      Main.qml

      import QtQuick
      
      Window {
          width: 640
          height: 480
          visible: true    
      
          Row {
              Rectangle {
                  width: 100
                  height: 100
                  color: "cyan"
      
                  MouseArea {
                      anchors.fill: parent
                      onClicked: console.log("Clicked cyan square")
                  }
              }
              Rectangle {
                  width: 100
                  height: 100
                  color: "green"
      
                  TapHandler {
                      onTapped: console.log("Tapped green square")
                  }
              }
          }
      }
      

       

      Steps to reproduce

      1. Build and run the attached example
      2. Click the cyan square
      3. Click the green square

       

      Output
      Step #2 (Expected):

      Main_QMLTYPE_0(0x25acc954110) QEvent::MouseButtonPress QPoint(49,50)
          Result: false
      QQuickMouseArea(0x25acc810750) QEvent::MouseButtonPress QPoint(49,50)
          Result: false
      Main_QMLTYPE_0(0x25acc954110) QEvent::MouseButtonRelease QPoint(49,50)
          Result: false
      QQuickMouseArea(0x25acc810750) QEvent::MouseButtonRelease QPoint(49,50)
          Result: false
      qml: Clicked cyan square
      

       

      Step #3 (Not Expected):

      Main_QMLTYPE_0(0x25acc954110) QEvent::MouseButtonPress QPoint(146,48)
          Result: false
      QQuickRectangle(0x25acc810e10) QEvent::MouseButtonPress QPoint(46,48)
          Result: false
      Main_QMLTYPE_0(0x25acc954110) QEvent::MouseButtonRelease QPoint(146,48)
          Result: false
      qml: Tapped green square
      

       

      Use-case
      Customer wants to implement custom, low-level event logging on Items of interest

      Attachments

        1. EventSpyStudy.zip
          2 kB
          Sze Howe Koh
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            srutledg Shawn Rutledge
            skoh-qt Sze Howe Koh
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes