Search code examples
qtqmlqt-quick

qml mousearea overlab not work in hoverenable mode


my problem is that mouseArea does not pass hover events. how can i fix this problem? in other words i want print 1 and 2 together in follow example.thanks.

Window {
visible: true
width: 640
height: 480
MouseArea{
    anchors.fill: parent
    hoverEnabled: true
    preventStealing: true
    propagateComposedEvents: true
    onPositionChanged: console.log("1")
}
MouseArea{
    anchors.fill: parent
    hoverEnabled: true
    preventStealing: true
    propagateComposedEvents: true
    onPositionChanged: {
        console.log("2")
    }
}

Solution

  • propagateComposedEvents only works for clicked, doubleClicked and pressAndHold events:

    This property holds whether composed mouse events will automatically propagate to other MouseAreas that overlap with this MouseArea but are lower in the visual stacking order. By default, this property is false.

    MouseArea contains several composed events: clicked, doubleClicked and pressAndHold. These are composed of basic mouse events, like pressed, and can be propagated differently in comparison to basic events.

    You could define your own custom QQuickItem that installs an event filter on the MouseArea, or alternatively just notify the other MouseArea about the hover events manually.