Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Providing precedence for onDoubleClicked over onClicked in QML

Providing precedence for onDoubleClicked over onClicked in QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 3 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Madesh R
    wrote on last edited by
    #1

    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: 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.

    1 Reply Last reply
    0
    • Shrinidhi UpadhyayaS Offline
      Shrinidhi UpadhyayaS Offline
      Shrinidhi Upadhyaya
      wrote on last edited by
      #2

      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")
              }
          }
      }
      

      Shrinidhi Upadhyaya.
      Upvote the answer(s) that helped you to solve the issue.

      M 1 Reply Last reply
      6
      • Pradeep P NP Offline
        Pradeep P NP Offline
        Pradeep P N
        wrote on last edited by Pradeep P N
        #3

        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.

        Pradeep Nimbalkar.
        Upvote the answer(s) that helped you to solve the issue...
        Keep code clean.

        M 1 Reply Last reply
        5
        • Shrinidhi UpadhyayaS Shrinidhi Upadhyaya

          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")
                  }
              }
          }
          
          M Offline
          M Offline
          Madesh R
          wrote on last edited by
          #4

          @Shrinidhi-Upadhyaya

          Thank you Shrinidhi :)

          1 Reply Last reply
          2
          • Pradeep P NP Pradeep P N

            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.

            M Offline
            M Offline
            Madesh R
            wrote on last edited by
            #5

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

            1 Reply Last reply
            2
            • Pradeep P NP Offline
              Pradeep P NP Offline
              Pradeep P N
              wrote on last edited by
              #6

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

              All the best.

              Pradeep Nimbalkar.
              Upvote the answer(s) that helped you to solve the issue...
              Keep code clean.

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved