Skip to content
Advertisement

How to distinguish between pressed, released and long press when using QAbstractButton::autoRepeat

I am using Qt 4.8.X on Linux with X11 and/or Qt-QWS with custom buttons derived from QAbstractButton. Now I have to distinguish between a button press, release and the user holding down the button. To do so, I would like to use QAbstractButton::autoRepeat as described in this question. As the QT Documentation states

If autoRepeat is enabled, then the pressed(), released(), and clicked() signals are emitted at regular intervals.

Well, how can I now distinguish between actually pressing down, holding down and releasing the button when all three Signals get emitted together? Your ideas are very welcome. Thanks and greeting.

Advertisement

Answer

Maybe using autoRepeat is not the best idea here. I do not know what you want to do exactly, but my first guess would be leaving autoRepeat off. If the user presses the button, you get your pressed signal. In that callback you can start a timer that fires in your desired “auto Repeat” interval. If the user releases the button again (signal released), your just stop or kill the timer.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement