13

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).

Konrad Madej
  • 1,271
  • 1
  • 11
  • 19

2 Answers2

4

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.

Deadron
  • 5,135
  • 1
  • 16
  • 27
  • Well for now I've added a property to the root component that contains the current mouse position (since that is the only information I am currently interested in). The position get's updated by the component's `MouseArea` as well as all underlying areas. Not too pretty and a bit hard to maintain (I have to remember to update that value in all underlying `MouseArea`s separately as you've mentioned) but it works. – Konrad Madej Aug 08 '13 at 10:39
1

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.

Stefan Monov
  • 11,332
  • 10
  • 63
  • 120
Evgeny Timoshenko
  • 3,119
  • 5
  • 33
  • 53