PDA

View Full Version : Double Click Capturing



ToddAtWSU
3rd July 2007, 13:42
I have some code that captures mousePressEvents, mouseReleaseEvents, mouseMoveEvents, and mouseDoubleClickEvents for a QGLWidget. I have it do many things based on which of the events occur. Inside my mouseReleaseEvent I have some code that is to only be executed if a double click did not occur. But when I would double click I noticed I was entering the release code.

I set up some break points and noticed on a double click the order of events is:

1. mousePressEvent
2. mouseReleaseEvent
3. mouseDoubleClickEvent
4. mouseReleaseEvent

Is there a way to tell if there is a double click event in the queue of mouse events because I would prefer to enter the double click event code first and then check the release event code and completely ignore the press event code if I double click. I am using Qt 3.3.7. Thanks for your help!

wysota
5th July 2007, 10:10
You could have a timer. Start the timer in the releaseEvent handler and make sure the timeout is long enough to handle the double click first. Then, in the double click event handler you can stop the timer and prevent it from firing. If a double click handler is not triggered, the timer will timeout and call a slot of your choice, where you can handle the single click. This is of course a nasty hack, but has a chance to work.

piotr.dobrogost
8th January 2011, 14:12
You might want to take a look at Raymond Chen's blog post titled Logical consequences of the way Windows converts single-clicks into double-clicks (http://blogs.msdn.com/b/oldnewthing/archive/2004/10/15/242761.aspx) where he describes the same technique Wysota does but makes some additional remarks on why it's a bad idea.