Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How does QT Handle overlapping mouse areas?



  • Hi,

    I am creating a plotting component, which has a MouseArea over the whole window for zooming and dragging. On top of this, I want to be able to set marks like this:

            Rectangle{
                id: recMark
                border.width: 0
                width: 1
                height: parent.height
                y: 0
                z: 5
                color: "red"
                opacity: 0.3
                visible: true
                MouseArea {
                    anchors.fill: parent
                    drag.target: recMark
                    drag.axis: Drag.XAxis
    
                }
            }
    

    Which MouseArea will be active if I click on this Rectangle? And is it possible to control which MouseArea is active?


  • Moderators

    @maxwell31 said in How does QT Handle overlapping mouse areas?:

    Which MouseArea will be active if I click on this Rectangle? And is it possible to control which MouseArea is active?

    The topmost one (determined by z value) will be "active" - it will catch mouse events.

    You can pass them on if you want your bottom one to get some events: in respective event slot set mouse.accepted = false and the event will be propagated further.

    All this is described in detail here: link.


Log in to reply