Widgets initial state



  • Hi,
    This is kind of embarrassing, but I cannot finger it out.
    I've created a form using Qt Designer, and this form is used in KDE application as a setup dialog (using KConfig XT). The form contains Check boxes and other widgets, like Spin boxes, line edits, etc. Each Check box should enable a number of other widgets, so I connect Check box's toggled(bool) signal with other widgets setEnabled(bool) slot.
    The dialog
    When I run the application, the dependent widgets are always enabled, despite the state of the Check box. I need to check and uncheck the Check box to get the widgets disabled. Of course, I can write a "manual" code to check the boxes in the form's constructor, and enable and disable, but since I have a lot of such widgets, I wonder if there is an "automated" way?

    Thanks,
    Darius


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    First thing to do is setup your widgets (including connections) and once that's done you can e.g. use QSettings to restore your application state i.e. get the QCheckBox value and apply it.

    Hope it helps



  • Thanks for your replay and welcome.
    I get the idea pretty well. I just wonder what can be done by the code auto-generated from the .ui file, and what must be hand-coded. As for now, the auto-generated code sets up the connections, and I had to write the code like:

    if( Settings::sine1() ){
          ui_prefs_base.kcfg_sine1A->setEnabled(true);
          ui_prefs_base.kcfg_sine1F->setEnabled(true);
          ui_prefs_base.kcfg_sine1rnd->setEnabled(true);
        }else{
          ui_prefs_base.kcfg_sine1A->setEnabled(false);
          ui_prefs_base.kcfg_sine1F->setEnabled(false);
          ui_prefs_base.kcfg_sine1rnd->setEnabled(false);
        }
    

    Does your answer mean this is unavoidable?

    Darius


  • Lifetime Qt Champion

    Why not use:

    ui_prefs_base.kcfg_sine1A->setEnabled(Settings::sine1());
    ui_prefs_base.kcfg_sine1F->setEnabled(Settings::sine1());
    ui_prefs_base.kcfg_sine1rnd->setEnabled(Settings::sine1());
    

    ?



  • Thank you, SGaist!
    More elegant, but still... "manual". Pretty easy for one Check box, annoying if you have plenty of them.
    Darius


  • Lifetime Qt Champion

    Then give object names to your widgets and use it to store their settings. Then use findChild when loading them


Log in to reply
 

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