303 views
in GUI Development by
Hi,

can somebody give some advise how to realise such function which t.e. would increment value while PushButton is depressed.

For example we would like to set time in a countdown timer. When we press button once it increments by +1, when we keep button depressed it increments faster.

It would be something like: while (buttons is depressed) do something.

Is there a better way to realise that without while loop? And finally how we can get the state of the PushButton (pressed, activated, released, etc.)?

1 Answer

+1 vote
by

Hello Raima,

the while-loop will block the UI. It is thus not the right approach. You should follow an event driven approach. When the button is pressed, the corresponding event is sent. When the button is released again, another event is sent. You can handle the events accordingly. If you want some operation to repeat while the button is pressed, use a Timer. For more details see:

Implement Push Button's slot methods for the button related events. Note there the events OnPress and OnRelease.

Using timers and animation effects: Timer.

Best regards

Paul Banach

 

by
Hi Paul,

thanks for your answer!
 

Can it be done in such a way (schematic flow):

OnPress - Button is 'depressed=1';

OnTimer - if(depressed==1) increment something;

OnRealease - Button is 'depressed=0'.

 

Thank you,

Raymond
by

Hello Raymond,

and know it is STILL  in depressed state as we do not want to press the same button twice - one time to start increment, another to stop.

I don't fully understand your application case. Do you want the button to behave like a toggle button? Or you even don't want this. Your question is not clear.

In any case you can track the button's current state. You can, for example, use a variable of type bool, which is set true in the slot method associated to button's OnPress property and it is set false in the slot method associated to button's OnRelease property. Then wherever you want to know the button's state, evaluate the value of this variable.

Best regards

Paul Banach

by
No it must be monostable PushButton which on single press increment +1. If you hold that button increment continues.

But I think now the question is solved. Thank you!
by

Hello Raymond,

the schematic flow is clear now. An idea: instead of using a variable to track the button's state, just start the timer in the OnPress event and stop the the timer in OnRelease event. As long as the timer is running, the timer will periodically increment the variable.

Best regards

Paul Banach

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...