问题
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 user releases the mouse? something like mousedown events in standard intervals? or do I have to implement this with a qtimer? thanks
回答1:
Check out QAbstractButton::autoRepeat and autoRepeatInterval. It should be exactly what you need and is available for all buttons.
回答2:
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.
回答3:
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.
来源:https://stackoverflow.com/questions/4896699/qt-button-to-emit-multiple-signals