Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically Toggle a Python PyQt 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?
like image 362
Nyxynyx Avatar asked Oct 22 '13 03:10

Nyxynyx


1 Answers

this should to the trick.

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.

like image 50
tom Avatar answered Sep 25 '22 03:09

tom