13
votes

Is it possible to propagate a MouseArea's positionChanged event to an underlying one?

I've tried to set the mouse.accepted to false for any existing signal handler of the top-most MouseArea as well as setting the propagateComposedEvents to true. Neither of those worked (although I'm not surprised with the propagateComposedEvents not working since the documentation says it only relays events like clicked, doubleClicked and pressAndHold).

2

2 Answers

3
votes

Depending on your structure you can always manually propagate the event by having your onPositionChanged handler call underlyingMouseArea.positionChanged(mouse) This should manually emit the signal in the underlying MouseArea. My only concern is that you might not be able to pass a MouseEvent object this way(never tried with anything other than a string). However, you can always perform this manual emit in C++ which definetly would not suffer from any type conversion issues.

1
votes

Unless you need to handle position change events with multiple mouse areas simultaneously you could try reparent your top mouse area:

import QtQuick 2.2
import QtQuick.Layouts 1.1

Rectangle {
    id: __root
    color: "lightgreen"
    width: 360
    height: 360

    Rectangle {
        id: rect2
        width: 100; height: 100
        color: "cyan"
        MouseArea {
            parent: __root // set 'logical' parent
            anchors.fill: rect2 // set 'visual' ancestor
            hoverEnabled: true

            onPositionChanged: {
                console.log('mouse area 2 onPositionChanged');
            }
        }
    }


    MouseArea {
        anchors.fill: parent
        hoverEnabled: true

        onPositionChanged: {
            console.log('mouse area 1 onPositionChanged');
        }
    }
}

There is an unresolved bugreport.