Mouse click Issue
-
Hello
I have written a simple program to receive mouse click events.
In which i have two slots, one for single click event and one for double click event.
now whenever i make double click, slot of single click is called first and then slot of double click.
what i was expecting is i should get only double click event instead of both events...
Is this proper behavior.??@
Item {
width: 300
height: 300MouseArea { id: mouseClick anchors.fill: parent onClicked: { console.log ("single click") } onDoubleClicked: { console.log ("double click") } }
}
@ -
-
If you don't want the single-click slot to be called if the user double-clicks, you could try this:
- Attach the onClicked signal to a slot that starts a Timer (with an interval of, say, 750ms)
- Connect the Timer's onTriggered signal to your real single-click slot
- If onDoubleClicked is emitted, then terminate the timer -- this stops the single-click slot from being called
Things to watch out for: Different systems can have different double-click "periods" (e.g. on my grandma's computer, if she makes 2 clicks 1 second apart, it still counts as a double-click). If your Timer interval is shorter than this, then both events will still be received.