1
votes

I have a Qt application. There I want to trigger some action while QPushButton is pressed and stop it when button is released. I have read a bit and so far what I found is to reimplement mousePressEvent to start timer to emit signals and do my action and also reimplement mouseReleaseEvent to stop that timer. Is there any other way or that one is the most correct one?

Thanks and regards

2
Just wanted to add: You do not need to reimplement QPushbutton for accessing these signals at all. Use connect() or (or Right Click>Go to slot if you're using Qt Designer Form) and you can code what you want to do on press or click.Aditya

2 Answers

3
votes

There are signals for pressed() and released() for QPushButton. Connect pressed() to activate whatever you want to be activated while the button is pressed, and stop it when released() is signaled.

1
votes

You can use the signal of pressed() and released() of QPushButton