PyQt5中如何判断按钮是否被连续按下?
对于我的应用,我需要只要按下按钮,我的升降系统就会上升,而当我不按下按钮时,它应该停止。
clicked() 函数不能用于此目的。然而,pressed() 和released() 函数也不起作用。
我在下面剪下了代码的相关部分。我的目标是只要按下按钮就打印“按下”文本
def __init__(self):
manual_button = QPushButton('Lift Button')
manual_button.pressed.connect(press_function)
self.manual_grid.addWidget(manual_button, 0, 1)
def press_function(self):
print('pressed')
谢谢
For my application, I need my lift system to go up as long as the button is pressed and it should stop when I don't press the button.
clicked() function is not functional for this purpose. However pressed() and released() functions also didn't work.
I snipped related section of my code below. My aim is to print "Pressed" text as long as button is pressed
def __init__(self):
manual_button = QPushButton('Lift Button')
manual_button.pressed.connect(press_function)
self.manual_grid.addWidget(manual_button, 0, 1)
def press_function(self):
print('pressed')
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需使用
按下
和释放
信号即可启动/停止QTimer
。像...Just use the
pressed
andreleased
signals to start/stop aQTimer
. Something like...