How distinguish mousepress an mousedoubleclick
-
Hi,
I have a trouble with mouse events on a widget.
I'm in Qt 5.9.
I start an action on mouse press event like begin a selection or start a drag...
On mouse double click I do another action like edit selected objetsThe trouble is :
mouse press is always called before a mouse double click
I must not have a selection and a edition in same time, in other world I wouldn't a mouse press event before
mouse double click.If I trace the execution, I have:
MdDocumentGLDisplay::mousePressEvent QEvent::Type(MouseButtonPress)
MdDocumentGLDisplay::mouseDoubleClickEvent
MdDocumentGLDisplay::mousePressEvent QEvent::Type(MouseButtonDblClick)How can I properly solve my problem ?
thanks,
Sorry for my english -
Yes, that's the way it works, but you can hack it.
Let's say you want action A on click, and action B on double click.
Instead of executing action A on a click immediately, you use a timer, set to about the application double click interval.
This way action A will get executed as the timer times out.
But if you get another click in that interval of time, you have a double click. So you check if the timer is running, and if it is you stop it. And then execute action B.
It will be easier to create an auxiliary widget that implements this behavior. It will delay click signals a little, but this way you won't get both a clicked and then a double clicked, you will either get clicked, or double clicked signal. Using signals will make it reusable, so you won't have to override the event methods, just hook whatever you want to the signals and you are set.