Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Widgets initial state

Widgets initial state

Scheduled Pinned Locked Moved General and Desktop
initial stateqt designersetenabled
6 Posts 2 Posters 1.8k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dbismor
    wrote on last edited by dbismor
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dbismor
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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());
          

          ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dbismor
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved