Disable standard button within QDialogButtonBox
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:
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?
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.
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?
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.
From within your dialog source file you can do something like this:
myButtonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
Thanks, didn't know that. You are the man ;)
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 :-)
Super! Thank you all!
if anybody cares the way you can do it with the QDialogButtonBox widget is:
(assuming your button box is called "buttonBox"):
flag = false