Disable OK button in ButtonBox (in mobile development)



  • 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]



  • 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);
    }
    }
    @



  • Indeed, I stumbled on this as well. An alternative approach is to use a single-shot timer that you trigger from the constructor.



  • Hi, thanks for the advice! Did it also work for you in emulator? Because I incorporated this method now but without an apparent effect.



  • I am working on desktop, not on the mobile. So sorry, I can't tell you if this works in the emulator.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.