Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QML - MouseArea - propagating onPositionChanged

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

like image 458
Konrad Madej Avatar asked Jul 30 '13 23:07

Konrad Madej


2 Answers

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.

like image 151
Deadron Avatar answered Nov 16 '22 02:11

Deadron


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.

like image 28
Evgeny Timoshenko Avatar answered Nov 16 '22 03:11

Evgeny Timoshenko