Disable OK button in ButtonBox (in mobile development)
-
wrote on 5 Apr 2011, 13:47 last edited by
I have a typical dialog window that is invoked from main window using a button via exec() call.
This window contain "buttonBox" that translates to standard "soft buttons" Ok and Cancel.
I want application to disable "OK" button till correct value is received from user in dialog.In dialog constructor I have:
@
ui->setupUi(this);
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
@but it does not affect the actual behaviour, the button is available and dialog is closed when it's pressed.
How I can disable/reenable a standard button in mobile app dialog?
[EDIT: code formatting, please use @-Tags, Volker]
-
wrote on 5 Apr 2011, 14:45 last edited by
This must be done in the show event. The buttons are enabled after the constructor :-( I had some similar problems and solved it by a flag (Initialised) and done it once in the show event.
@
myDialog::showEvent()
{
if(!initialized)
{
initialized = true;
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
}
}
@ -
wrote on 5 Apr 2011, 15:08 last edited by
Indeed, I stumbled on this as well. An alternative approach is to use a single-shot timer that you trigger from the constructor.
-
wrote on 6 Apr 2011, 16:08 last edited by
Hi, thanks for the advice! Did it also work for you in emulator? Because I incorporated this method now but without an apparent effect.
-
wrote on 6 Apr 2011, 17:26 last edited by
I am working on desktop, not on the mobile. So sorry, I can't tell you if this works in the emulator.
2/5