Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. TapHandler: stop propagation
Forum Updated to NodeBB v4.3 + New Features

TapHandler: stop propagation

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 1.6k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • pieterbekaertP Offline
    pieterbekaertP Offline
    pieterbekaert
    wrote on last edited by
    #1

    I am totally confused as to how tapping do or do not get propagated to "lower" handlers.

    Consider following QML:

    import QtQuick 2.12
    import QtQuick.Controls 2.12
    import QtQuick.Window 2.12
    
    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
    
        Rectangle {
            anchors.fill: parent
    
            TapHandler {
                onTapped: console.log("covered tapped")
            }
        }
    //    Popup {
    //        visible: true
    //        width: parent.width
    //        height: parent.height
          Text { // Change this to Button
              text: "Click me"
              anchors.fill: parent
              TapHandler {
                  onTapped: console.log("top tapped")
              }
    //        }
        }
    }
    
    

    If you click the text, both "top tapped" as well as "covered tapped" is displayed.
    I do not want this to happen.
    Even if you put the Popup element in between (by uncommented the commented lines), both are displayed.
    If you change the "Text" element into "Button", only "top tapped" is displayed.

    The Button behavior is as expected: if you click a button, you do not want underlying items to get this event too. But I would expect the same with a Popup in between. And I would like to set properties on the top TapHandler to avoid propagation also in the Text case.

    I have read and reread the documentation, as well as search the internet, but I do not get a clue as to how to solve this properly.

    [I did find other related posts in this forum, but they did not elaborate on the alternative behaviors, and they were not resolved IMO.]

    raven-worxR 1 Reply Last reply
    0
    • pieterbekaertP pieterbekaert

      I am totally confused as to how tapping do or do not get propagated to "lower" handlers.

      Consider following QML:

      import QtQuick 2.12
      import QtQuick.Controls 2.12
      import QtQuick.Window 2.12
      
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      
          Rectangle {
              anchors.fill: parent
      
              TapHandler {
                  onTapped: console.log("covered tapped")
              }
          }
      //    Popup {
      //        visible: true
      //        width: parent.width
      //        height: parent.height
            Text { // Change this to Button
                text: "Click me"
                anchors.fill: parent
                TapHandler {
                    onTapped: console.log("top tapped")
                }
      //        }
          }
      }
      
      

      If you click the text, both "top tapped" as well as "covered tapped" is displayed.
      I do not want this to happen.
      Even if you put the Popup element in between (by uncommented the commented lines), both are displayed.
      If you change the "Text" element into "Button", only "top tapped" is displayed.

      The Button behavior is as expected: if you click a button, you do not want underlying items to get this event too. But I would expect the same with a Popup in between. And I would like to set properties on the top TapHandler to avoid propagation also in the Text case.

      I have read and reread the documentation, as well as search the internet, but I do not get a clue as to how to solve this properly.

      [I did find other related posts in this forum, but they did not elaborate on the alternative behaviors, and they were not resolved IMO.]

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @pieterbekaert
      you should accept the tap event in order to stop the propagation.
      E.g. add "eventPoint.accepted = true" in the handler

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • pieterbekaertP Offline
        pieterbekaertP Offline
        pieterbekaert
        wrote on last edited by pieterbekaert
        #3

        @raven-worx said in TapHandler: stop propagation:

        eventPoint.accepted = true

        This does not do the trick.
        The accepted property is read-only and "cannot be usefully set from QML"
        https://doc.qt.io/qt-5/qml-qtquick-eventpoint.html#accepted-prop

        There seems to be a "solution" by setting the gesturePolicy on the top TapHandler:

        gesturePolicy: TapHandler.ReleaseWithinBounds

        This is suggested in
        https://interest.qt-project.narkive.com/hd4hqQkH/qml-pointer-handlers-how-to-use-grabpermissions
        This IMO if a far from intuitive hack...

        1 Reply Last reply
        1
        • M Offline
          M Offline
          Moia
          wrote on last edited by
          #4

          As you already figured out, GrabPermission will do the trick as inteded.

          https://doc.qt.io/qt-5/qml-qtquick-taphandler.html#grabPermissions-prop

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved