qt button to emit multiple signals

大兔子大兔子 提交于 2019-12-11 05:39:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!