I want to handle pressed and released signals in two overlapping Mouseareas.
Brief explanation of my case is as follows:
I have two mouse areas M1 and M2. M1 is contained by a rectangle, which serves as a button. It has a fixed size, e.g.100x100. M2 fills the whole screen and definitely larger in size than M1. I can set the z properties of M1 and M2 arbitrarily. I need to handle pressed and released signals in both of these Mouseareas.
Is it possible in QtQuick and if so, how?
import QtQuick 2.5
Item {
visible: true
width:1280
height:720
Rectangle {
color: "blue"
width: 100; height: 100
z:1
MouseArea {
id:m1
anchors.fill: parent
onPressed : {
mouse.accepted = false
console.log("pressed m1")
}
onReleased: {
console.log("released m1")
}
}
}
MouseArea {
id: m2
anchors.fill: parent
onPressed : {
console.log("pressed m2")
}
onReleased: {
console.log("released m2")
}
}
}
I want to get pressed and released for both Mouseareas when m1 is pressed and released.
(Qt Version 5.5)
First of all,
ids cannot begin with capital letters, so yourMouseAreas can't beM1andM2. Instead they have to be m1 and m2.Edit: I have borrowed the idea of
m1.released(mouse)from the answer by sk2212, and tweaked a little to handle the case when the mouse is outside ofm1and is pressed and released.