以编程方式切换 Python PyQt QPushbutton [英] Programmatically Toggle a Python PyQt QPushbutton

查看:41
本文介绍了以编程方式切换 Python PyQt QPushbutton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以以编程方式切换 QPushButton?我有一个可检查的 QPushButton,用户按下它来启动一个进程.流程完成后,如何将按钮的状态更改为未选中?

Is it possible to programmatically toggle a QPushButton? I have a checkable QPushButton that a user presses to start a process. When the process is done, how can the button's state be changed to unchecked?

runBtn = QPushButton('Run')
runBtn.setCheckable(True)
runBtn.clicked.connect(runProcess)

def runProcess():
    time.sleep(5)
    runBtn.uncheck()    # how should this be done?

推荐答案

这应该是诀窍.

runBtn.setChecked(False)

虽然这不是理想的行为.切换按钮应该用于打开和关闭事物,而不是指示正在进行的事情.如果有些事情需要时间,您应该将光标更改为等待光标,并且最好仍然显示进度条/对话框.

although that's not ideal behaviour. toggle buttons should be used for turning things on and off, not indicating that something is in progress. if something is taking time you should change the cursor to a wait cursor and better still show a progress bar/dialog.

这篇关于以编程方式切换 Python PyQt QPushbutton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆