I want to write a if
with a condition as the state of QPushButton
. I would like to execute if
if the button is enabled. So, how can i check the state of the Button.
Code:
self.pushButton = QtGui.QPushButton()
self.pushbutton.setEnabled(False)
self.pushbutton.setEnabled(False) ##some where in the another class I have enabled it this line will not be executed all the time,so I want the check state.
if self.pushbutton.checkstate() == Enabled: ##??? How to write this condition?
some code I want to execute
Use
QPushButton.isEnabled
. The following code toggles a button between enabled and disabled and uses an "if" test to do something depending on the state. It is for PyQt5 but you should only have to adjust the imports to make it work with PyQt4 (if you are using Python 2.x, you will also have to adjust the print statements):