Disable standard button within QDialogButtonBox
-
wrote on 28 Jul 2011, 17:26 last edited by
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 -
wrote on 28 Jul 2011, 17:33 last edited by
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. -
wrote on 28 Jul 2011, 17:36 last edited by
I created this dialog using Qt Designer, so I don't actually have a constructor. How can I define the standard buttons without a constructor?
-
wrote on 28 Jul 2011, 17:41 last edited by
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.
-
wrote on 28 Jul 2011, 17:44 last edited by
From within your dialog source file you can do something like this:
@
myButtonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
@ -
wrote on 28 Jul 2011, 17:47 last edited by
Thanks, didn't know that. You are the man ;)
-
wrote on 28 Jul 2011, 17:51 last edited by
No problem. There's so many aspects to Qt now that it is virtually impossible for anyone to know all of it in detail. But that's why I like these forums and wiki, there's always some new little trick or technique to be found :-)
-
wrote on 28 Jul 2011, 17:52 last edited by
Super! Thank you all!
-
wrote on 20 Oct 2011, 20:07 last edited by
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)