Disable standard button within QDialogButtonBox
-
Hello -
I have a QDialogButtonBox that contains 2 standard buttons: QDialogButtonBox::Ok and QDialogButtonBox::Cancel.
I would like to be able to disable the okay button if certain conditions aren't met. However upon doing the following:
@QDialogButtonBox::Ok.setEnabled (false);@
I get an error message:
error: request for member 'setEnabled' in (QDialogButtonBox::StandardButton)1024u', which is of non-class type 'QDialogButtonBox::StandardButton'.So, if I use a QDialogButtonBox, I cannot use setEnabled, but is there and equivalent for this?
Thanks,
Kate -
Hi Kate,
you should be able to define the standard buttons through this "constructor":http://doc.qt.nokia.com/4.7/qdialogbuttonbox.html#QDialogButtonBox-3
That should do the trick as long as you do not have to switch it later during runtime, I guess. -
you can drag a QDialogButtonBox in your form and then set the flags in the properties on the right.
Scroll down almost to the bottom and you'll see Standardbuttons. just check the choices you want.About your question to set your ok button not enabled while your cancel buttons stays active:
you used the OK enum and that doesn't represent the okbutton, it's just a flag like you can set in QT Designer as explained before.If I were you I would use 2 different pushbuttons one with OK and one with Cancel on it. Then you can enable/disable them seperately.
-
if anybody cares the way you can do it with the QDialogButtonBox widget is:
(assuming your button box is called "buttonBox"):
flag = false
self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(flag)