Important: Please read the Qt Code of Conduct -

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?


  • 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() ){

    Does your answer mean this is unavoidable?


  • Lifetime Qt Champion

    Why not use:



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

  • Lifetime Qt Champion

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