qt button to emit multiple signals
is there a Qt (I use Qt 4.7.1) widget that emit signals (not just one at the first time) while it is pressed and stops when the use开发者_运维百科r releases the mouse? something like mousedown events in standard intervals? or do I have to implement this with a qtimer? thanks
Check out QAbstractButton::autoRepeat and autoRepeatInterval. It should be exactly what you need and is available for all buttons.
You have to implement something that fire the event until the user release the mouse.
I suggest you to create an handler class connected to the button event that fires custom events as you like to its observers.
As far as I know there is no such button widget.The QPushButton
's autoRepeat
should do just what you want. But would not the QPushButton::pressed()
and QPushButton::released()
signals be enought for your needs?
Anyway, what you are describing would be quite easy (and redundant, since it already exists) to implement, connect the QTimer::timeout()
signal to the signal you want and then just start the timer on pressed()
signal and stop it on released()
signal :)
Edit: As pointed out in comments, there is an inbuild solution and that is setting property autoRepeat
inherited from QAbstractButton
to true
.
You can customise the initial delay and interval by adjusting autoRepeatDelay
and autoRepeatInterval
.
精彩评论