Results 1 to 4 of 4

Thread: Push button double click

  1. #1
    Join Date
    Feb 2006
    Posts
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Push button double click

    If you have a button on a dialog that you connect to the clicked signal which has a slot that calls accept() to close the window, if you double click the button fast enough you can end up with 2 calls to accept. I know I can work around this by disabling the button in the slot and re-enabling on show, but it seems like that shouldn't be neccessary. When would you want a button click to be triggered on a window that has already been hidden?

    here's a quick example. If you double click the button, you get okOn printed twice
    Qt Code:
    1. #include <qapplication.h>
    2. #include <qdialog.h>
    3. #include <qpushbutton.h>
    4. #include <iostream>
    5.  
    6. class MyDialog : public QDialog
    7. {
    8. Q_OBJECT
    9. public:
    10. MyDialog(QWidget *parent = 0)
    11. : QDialog( parent, 0, FALSE, WDestructiveClose )
    12. {
    13. okBtn = new QPushButton( "&Ok", this );
    14. connect( okBtn, SIGNAL( clicked() ), this, SLOT( onOk() ) );
    15. }
    16.  
    17. protected slots:
    18. void onOk()
    19. {
    20. std::cout << "onOk" << std::endl;
    21. sleep(1);
    22. accept();
    23. }
    24.  
    25. private:
    26. QPushButton* okBtn;
    27. };
    28.  
    29. int main(int argc, char **argv)
    30. {
    31. QApplication a(argc, argv);
    32.  
    33. QDialog mainWin(0);
    34. a.setMainWidget(&mainWin);
    35.  
    36. MyDialog *t = new MyDialog(0);
    37. t->show();
    38.  
    39. return a.exec();
    40.  
    41. }
    42.  
    43. #include "qtDialogExample.moc"
    To copy to clipboard, switch view to plain text mode 

    Thanks,
    Curt

  2. #2
    Join Date
    Feb 2006
    Location
    Österreich
    Posts
    35
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Push button double click

    Sorry, but I didn't understand from the message. What exactly is your question? How to ignore the second call? Or how to specifically handle a double click?

    If it is the latter you would intercept the MouseEvent and compare the event's type() with the constant QEvent::MouseButtonDblClick (probably in an if-else or switch()-case statement). If you want to know how to avoid it calling twice, maybe just have a static variable in your subclass implementation which is initialized in the class constructor, then let your new event handler only process the event if the variable is false, otherwise ignore() and pass the data on to the parent. That way the variable dies when the class is destructed and is only run once.
    Last edited by michel; 14th February 2006 at 22:51. Reason: Misspelled a function name
    My philosophy is: If you can use a free, open-source alternative: do it. And if you can't, pretend it's free and open-source and hope you don't get caught.

  3. #3
    Join Date
    Feb 2006
    Posts
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Push button double click

    My question is why would qt allow this. If the dialog has been closed and there is a buffered click action, shouldn't it just ignore that second click? When the signal is issued, the button is hidden. Working around this is easy enough. It just doesn't seem correct to issue a clicked signal from a button that is hidden.

  4. #4
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Push button double click

    Quote Originally Posted by curtisw
    My question is why would qt allow this. If the dialog has been closed and there is a buffered click action, shouldn't it just ignore that second click? When the signal is issued, the button is hidden. Working around this is easy enough. It just doesn't seem correct to issue a clicked signal from a button that is hidden.
    It wasn't hidden when you did the second click - so the behaviour is quite correct.
    Save yourself some pain. Learn C++ before learning Qt.

Similar Threads

  1. Double Click Capturing
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2011, 14:12
  2. Replies: 2
    Last Post: 11th January 2009, 23:24
  3. QPaintEvent on button click?
    By vishal.chauhan in forum Qt Programming
    Replies: 1
    Last Post: 5th June 2007, 08:44
  4. QGraphicsScene Click / Double Click
    By philentropist in forum Qt Programming
    Replies: 1
    Last Post: 9th February 2007, 04:32
  5. Replies: 5
    Last Post: 12th January 2006, 15:40

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.