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

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

    }
    @



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


  • Moderators

    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.



  • yes, i already tried the timer thing. thanks.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.