Three-click
-
How to handle three clicks one after the other?
If between 2nd and 3rd click is large time interval - is not three click, must be enough short time interval.
I wanna use it to select current line.Use a QElapsedTimer to measure time between mouse releases. If it's under some delta increase click counter. If above reset it. When you reach a count of 3 emit a triple click signal.
Something like this:
void SomeWidget::mouseReleaseEvent(QMouseEvent* event) { ParentClass::mouseReleaseEvent(event); qint64 elapsed = someTimer.restart(); //someTimer is QElapsedTimer member if (elapsed < someDelta) ++clicks; else clicks = 1; switch(clicks) { case 1: emit singleClick(); break; case 2: emit doubleClick(); break; case 3: emit tripleClick(); break; case 4: emit quadrupleClick(); break; ... } }
-
Will no conflict with standard
QWidget:: mouseDoubleClickEvent?
will two times QWidget:: mouseReleaseEvent and one QWidget:: mouseDoubleClickEvent ?@AndrzejB It was just an example. You don't have to make all those signals. You can just leave the triple signal and use the default ones for single and double clicks, or you can make a
mouseTripleClickEvent
or call a callback function or do whatever else you need. I just gave you a way to detect the third click. How you handle it when you do is up to you. -
Will no conflict with standard
QWidget:: mouseDoubleClickEvent?
will two times QWidget:: mouseReleaseEvent and one QWidget:: mouseDoubleClickEvent ?@AndrzejB said in Three-click:
Will no conflict with standard
QWidget:: mouseDoubleClickEvent?Yes, and the double click event will always conflict with the single click. However, the double click can only occur (and thus will be handled) after the single click. In the same way the triple click can only occur after the double click.
Somewhere in the back of my mind I remember that there is a GUI guideline stating that a double click should not do something totally unrelated to the single click as to not confuse users. The first click positions the cursor; the second click selects the word under the current cursor; the third click would now select the whole line (which will contain the currently selected word). Every click is thus an extension of the previous one. There will be no problem in first handling the single click, after that the double click, and finally the triple click. Otherwise you will have to delay the action of the click using a QTimer and some boolean variables to check if the single wasn't overridden with a double click and the double click wasn't overridden with a triple click.