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. Mouse click Issue
Forum Updated to NodeBB v4.3 + New Features

Mouse click Issue

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 3.0k 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.
  • A Offline
    A Offline
    aekam
    wrote on last edited by
    #1

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

    MouseArea {
        id: mouseClick
        anchors.fill: parent
    
        onClicked: {
            console.log ("single click")
        }
    
        onDoubleClicked: {
            console.log ("double click")
        }
    }
    

    }
    @

    If you take care of inches, you won't have to worry about miles... :)

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bomb3rman
      wrote on last edited by
      #2

      Well what you describe is the behavior I would expect ... The clicked signal is emitted after you click first. At this point, Qt does not know, that a second click is following. After the second click only the doubleClicked signal should be emitted.

      1 Reply Last reply
      0
      • JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        If you don't want the single-click slot to be called if the user double-clicks, you could try this:

        1. Attach the onClicked signal to a slot that starts a Timer (with an interval of, say, 750ms)
        2. Connect the Timer's onTriggered signal to your real single-click slot
        3. 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.

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        0
        • A Offline
          A Offline
          aekam
          wrote on last edited by
          #4

          yes, i already tried the timer thing. thanks.

          If you take care of inches, you won't have to worry about miles... :)

          1 Reply Last reply
          0

          • Login

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