Results 1 to 5 of 5

Thread: Recognise double click

  1. #1
    Join Date
    May 2019
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Recognise double click

    Hello, how my program can recognise if I double clicked selected button?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Recognise double click

    You can solve this problem in at least these three ways:

    - implement and install an event filter (QObject::installEventFilter()) on the QPushButton instance and look for QWidget::mouseDoubleClickEvent() events

    - derive a new class from QPushButton and override the mouseDoubleClick() event

    - implement slots for QAbstractButton::pressed() and QAbstractButton::released() signals. In the pressed slot, you will start a single-shot QTimer with a timeout set to QApplication::doubleClickInterval(). You will also set a counter to count the number of presses. In the released slot, you will check to see if the timer is still running and check the number of presses count. If the count is 2 and the timer is still running, it means the user has clicked the mouse twice, fast enough to be a double click. If the timeout fires before two released() signals are received, then that means either a click or two clicks depending on the count. If your released slot does detect a double click, set the counter to zero and stop the timer so you can get ready for the next double click. In the timeout slot, you should also set the counter to zero.

    In any case, your button will still emit clicked(), pressed(), released(), and toggled() signals, so if you want to ignore single clicks, you should not connect slots to clicked() or toggled().

    There is a reason why there is no double-clicked signal for push buttons - it is not normal behavior and goes against most user interface guidelines. So if you implement it, your users will be confused when they click a button once (as is the normal behavior) and nothing happens. They will not be expecting to have to double-click the button to get a response.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    May 2019
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Recognise double click

    Selected button I meant Selected button by user ("W" or "S" or LeftMouseButton) out of GUI / in other app. I heard I can do it using QTimer, but I dont know how.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Recognise double click

    Selected button I meant Selected button by user ("W" or "S" or LeftMouseButton) out of GUI / in other app.
    I am sorry, but I have no idea what you mean. Maybe you can explain in more than one sentence?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    May 2019
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Recognise double click

    I want to do an app, what can alert / output / notify user when he double click keyboard button or mouse button.

    Notification is simple, but I dont know how I can catch double click.

Similar Threads

  1. Replies: 2
    Last Post: 19th May 2014, 19:25
  2. Replies: 4
    Last Post: 11th January 2014, 04:06
  3. Telling apart single click and double click in QTableView
    By jgirlich in forum Qt Programming
    Replies: 1
    Last Post: 5th March 2013, 15:27
  4. Replies: 2
    Last Post: 16th July 2012, 13:40
  5. Replies: 2
    Last Post: 12th January 2009, 00:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.