Unsolved Push button long&short time press control
-
Hi,
I want to control a pushbutton long or short time pressed status with a timer. If i use with "::on_pushButton_pressed()" and "::on_pushButton_released()" how can i check the pressed time ? Or which way must i use ? -
Hi
You want to know how long a user hold down the button?
There is
http://doc.qt.io/qt-5.5/qelapsedtimer.html#details -
@mrjj
Yes, i want to know if button pressed short and released or it is pressed long time (maybe 1000ms). first i think maybe a timer can be defined globally and button pressed and released functions can be used to control the short or long press, but i can not use a global timer , you maybe give idea more clearly. -
Ok, it doesn't have to be global, but could live
in the class that has ::on_pushButton_XXAlternatively you could subclass QPushButton and create one
that can do this it self ? (internal handling of the QElapsedTimer)Can I ask why you need to know this?
Most will just click it and released will come very fast. -
@mrjj
Because my button must do 2 different work according to the short or long press. if it is pressed short, it execute a mission and if it is pressed long it executes another different work. -
@rapid84
ok. I understand.
There is also
http://doc.qt.io/qt-5.5/qabstractbutton.html#autoRepeat-prop
You could just "count" and use the count to decide if function 1 or 2.If you need this for more that 1 button, a new Button type is the way to go.
You could even make new signal giving the pressed time or count. -
@mrjj
As far as i understand autoRepeat() make buttons do same thing periodically,( am i right ? ) . But i want my button do something "only once" as far as it is pressed long until it is released . -
@rapid84
yes, it often used for that. But you could also use it to keep track of
how long it was pressed.
Since it will also give mutiple released , i guess using
QElapsedTimer is easier.