QML mouse handlers
Unsolved
QML and Qt Quick
-
Hi can you help me with this mouse event propagation problem? I'm writing on QML Qt 5.9 (MuseScore3 Plugin).
Following is simplified from Listview for discussion, in real usage the num of buttons is dynamic
Thank youAim
While pressing one button, drag and move to trigger other buttons
Similar to painting raster pixelsCase 1
Itembutton1 MouseArea.onPressed with mouse.accepted=false MouseArea.onReleased Itembutton2 MouseArea.onPressed with mouse.accepted=false MouseArea.onReleased
Question 1
Is it true while I keep pressing button1 , MouseAction is attached to button1, and there's no way to trigger click/hover on button2 ?
Case 2
Logic 2
Itembutton1 MouseArea.onPressed with mouse.accepted=false //MouseArea.onEntered (commented out, not using) MouseArea.onReleased Itembutton2 MouseArea.onPressed with mouse.accepted=false MouseArea.onEntered MouseArea.onReleased
Question 2
Why is .onReleased of button2 not triggerable?
QML for Case 2
can test this online at https://qmlonline.kde.org/
import QtQuick 2.9 import QtQuick.Controls 2.2 Item{ id:multiclick property bool isPressing:false Item{ width: 50; height: 50; id:button1 property bool m:false Rectangle { anchors.fill: parent; color: parent.m ? "#c00000" : "lightgrey" Text{ anchors.fill:parent; horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter; font.pointSize: 20; text: 'M' } MouseArea{ anchors.fill: parent acceptedButtons: Qt.LeftButton z:2 onPressed:{ mouse.accepted=false console.log('1 pressed') console.log('multiclick.isPressing: ',multiclick.isPressing) multiclick.isPressing=true } } //MouseArea{ // anchors.fill: parent // acceptedButtons: Qt.LeftButton // z:1 // hoverEnabled: true // onEntered:{ // console.log('1 entered') // console.log('multiclick.isPressing: ',multiclick.isPressing) // if(multiclick.isPressing) parent.parent.m=true // } //} MouseArea{ anchors.fill: parent acceptedButtons: Qt.LeftButton z:-1 onReleased:{ console.log('1 released') console.log('multiclick.isPressing: ',multiclick.isPressing) multiclick.isPressing=false } } } } Item{ width: 50; height: 50; anchors.top:button1.bottom id:button2 property bool m:false Rectangle { anchors.fill: parent ; color: parent.m ? "#c00000" : "lightgrey" Text{ anchors.fill:parent; horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter; font.pointSize: 20; text: 'M' } MouseArea{ anchors.fill: parent acceptedButtons: Qt.LeftButton z:2 onPressed:{ mouse.accepted=false console.log('2 pressed') console.log('multiclick.isPressing: ',multiclick.isPressing) multiclick.isPressing=true } } MouseArea{ anchors.fill: parent acceptedButtons: Qt.LeftButton z:1 hoverEnabled: true onEntered:{ console.log('2 entered') console.log('multiclick.isPressing: ',multiclick.isPressing) if(multiclick.isPressing) parent.parent.m=true } } MouseArea{ anchors.fill: parent acceptedButtons: Qt.LeftButton z:-1 onReleased:{ console.log('2 released') console.log('multiclick.isPressing: ',multiclick.isPressing) multiclick.isPressing=false } } } } }