Providing precedence for onDoubleClicked over onClicked in QML
-
Hi ,
I have a mouse area defined inside QML file,
Is it possible to provide precedence to mouse events,
Such as onDoubleCliked should be called first over onClicked.
Will I be able to differenciate among these two events.Ex.
MouseArea {
id:mouseArea
anchors.fill: parentonDoubleClicked: {
//I need to execute only this if it occurs ,terminate the execution passing to next mouse event
console.log ("double click accepted")
}onClicked: {//Execute this piece of code if mouse previous event didn't occur console.log ("single click accepted") } }
Thank you.
-
Hi @Madesh-R , i dont think so there is a property in MouseArea where you can set the preference for DoubleClick over the Click.
I have written a sample code by using a timer,its just a workaround:-
Timer { id: dummyTimer interval: 100 running: false onTriggered: { console.log("Clicked") } } Rectangle { height: 100 width: 100 color: "red" MouseArea { anchors.fill: parent onClicked: { dummyTimer.start() } onDoubleClicked: { dummyTimer.stop() console.log("Double Clicked") } } }
-
Hi @Madesh-R
Adding to @Shrinidhi-Upadhyaya solution.
A small explanation from the MouseArea QML TypedoubleClicked() :
- This signal is emitted when there is a double-click (a press followed by a release followed by a press).
clicked() :
- This signal is emitted when there is a click.
- A click is defined as a press followed by a release, both inside the MouseArea (pressing, moving outside the MouseArea, and then moving back inside and releasing is also considered a click).
Hence when ever you perform the
double-click
(press, release, press) it will initially call theclicked
(press, release) event.All the best.
-
Thank you Shrinidhi :)
-
@Pradeep-P-N
Thank you Pradeep. :) -
@Madesh-R
If you have the solution please mark it as SOLVED.All the best.