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. How to Prevent overlapping HoverHandler steals event?
Forum Updated to NodeBB v4.3 + New Features

How to Prevent overlapping HoverHandler steals event?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 4 Posters 1.0k Views 1 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.
  • A Offline
    A Offline
    arun-holoplot
    wrote on last edited by
    #1

    I have two overlapping rectangles with HoverHandlers in them.

    As soon as I hover over the top left corner of the Bottom Rectangle, the Top Rectangle's HoverHandler receives the event.

    On the right side, you can see that they are using MouseAreas. I would like to achieve the same result with HoverHanlder.

    Is there any way to achieve this behavior?

    I tried setting grabPermissions: PointerHandler.TakeOverForbidden for the HoverHandler, but it didn't work.

    import QtQuick 2.15
    import QtQuick.Window 2.15
    import QtQuick.Shapes 1.15
    
    Window {
        width: 760
        height: 480
        visible: true
        title: qsTr("HoverHandler Test")
    
    
        Rectangle {
            width: 150
            height: 100
            color: handler1.hovered ? "orange" : "grey"
            border.color: "black"
            x: 100
            y: 200
    
            Text {
                x: 10
                y: 10
                text: "HoverHandler"
            }
    
            HoverHandler {
                id: handler1
                grabPermissions: PointerHandler.TakeOverForbidden
                cursorShape: Qt.SizeVerCursor
            }
        }
    
        Rectangle {
            width: 150
            height: 100
            color: handler2.hovered ? "red" : "grey"
            border.color: "black"
            x: 200
            y: 250
    
            HoverHandler {
                id: handler2
                grabPermissions: PointerHandler.TakeOverForbidden
                cursorShape: Qt.SizeHorCursor
            }
        }
    
    
        Rectangle {
            width: 150
            height: 100
            color: mouseArea1.hovered ? "orange" : "grey"
            border.color: "black"
            x: 400
            y: 200
    
            Text {
                x: 10
                y: 10
                text: "MouseArea"
            }
    
            MouseArea {
                id: mouseArea1
                anchors.fill: parent
                property alias hovered: mouseArea1.containsMouse
                hoverEnabled: true
                cursorShape: Qt.SizeVerCursor
            }
        }
    
        Rectangle {
            width: 150
            height: 100
            color: mouseArea2.hovered ? "red" : "grey"
            border.color: "black"
            x: 500
            y: 250
    
            MouseArea {
                id: mouseArea2
                anchors.fill: parent
                property alias hovered: mouseArea2.containsMouse
                cursorShape: Qt.SizeHorCursor
                hoverEnabled: true
            }
        }
    }
    
    
    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      See if changing this: https://doc.qt.io/qt-5/qml-qtquick-hoverhandler.html#acceptedButtons-prop to Qt.NoButton keeps it from stealing click events.

      C++ is a perfectly valid school of magic.

      M 1 Reply Last reply
      0
      • L Offline
        L Offline
        lemons
        wrote on last edited by
        #3

        assuming this is the intended behavior, you could simply disable the lower one while the upper one is hovered.

        HoverHandler {
            id: handler1
            enabled: !handler2.hovered
            cursorShape: Qt.SizeVerCursor
        }
        
        A 1 Reply Last reply
        0
        • L lemons

          assuming this is the intended behavior, you could simply disable the lower one while the upper one is hovered.

          HoverHandler {
              id: handler1
              enabled: !handler2.hovered
              cursorShape: Qt.SizeVerCursor
          }
          
          A Offline
          A Offline
          arun-holoplot
          wrote on last edited by
          #4

          @lemons This does not work for me since the rectangles were created dynamically in the real case, and there will be more than two

          1 Reply Last reply
          0
          • fcarneyF fcarney

            See if changing this: https://doc.qt.io/qt-5/qml-qtquick-hoverhandler.html#acceptedButtons-prop to Qt.NoButton keeps it from stealing click events.

            M Offline
            M Offline
            Mammamia
            wrote on last edited by
            #5

            @fcarney hmm, Unfortunately It didn't. :(

            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