Omkar
Omkar

Reputation: 21

How to disable a particular standard button in pyqt

I am working on python application where I have created the dialog which includes several standard buttons like: Reset, OK, Cancel, Apply. here is the relevant code for the standard button,

self.buttonBox = QtGui.QDialogButtonBox(ROI)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Reset|QtGui.QDialogButtonBox.Apply|QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName( ("buttonBox"))

My question is how to disable only Apply button Even I tried the following code

QtGui.QDialogButtonBox.Apply.setEnabled(False)

but getting error

AttributeError: 'StandardButton' object has no attribute 'setEnabled'

So how do I disable particular button in set of standard button

Upvotes: 2

Views: 5523

Answers (2)

bugmenot123
bugmenot123

Reputation: 1136

@Omkar's comment as answer:

You need to find the specific object and then call its setEnabled() method with False as parameter.

For your QDialogButtonBox you can get to the specific button via

btn_apply = self.buttonBox.button(QtGui.QDialogButtonBox.Apply)

and then disable using

btn_apply.setEnabled(False)

Alternatively this can be done in one step:

self.buttonBox.button(QtGui.QDialogButtonBox.Apply).setEnabled(False)

See https://doc.qt.io/qt-5/qdialogbuttonbox.html#button for a reference on the button "retrieval" and https://doc.qt.io/qt-5/qwidget.html#enabled-prop for the disabling.

Upvotes: 2

Ravi Dutt Sharma
Ravi Dutt Sharma

Reputation: 16

i have not used it very extensively but think there can be one solution

try using .setVisible kind of api if you can find from readthedoc website for pyqt

Upvotes: 0

Related Questions