Qt World Summit: Register Today!

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.

    MouseArea {
    anchors.fill: parent

            onDoubleClicked: {

    //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: {
    Rectangle {
        height: 100
        width: 100
        color: "red"
        MouseArea {
            anchors.fill: parent
            onClicked: {
            onDoubleClicked: {
                console.log("Double Clicked")

  • Hi @Madesh-R

    Adding to @Shrinidhi-Upadhyaya solution.
    A small explanation from the MouseArea QML Type

    doubleClicked() :

    • 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 the clicked (press, release) event.

    All the best.

  • @Shrinidhi-Upadhyaya

    Thank you Shrinidhi :)

  • @Pradeep-P-N
    Thank you Pradeep. :)

  • @Madesh-R
    If you have the solution please mark it as SOLVED.

    All the best.

Log in to reply