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. dynamically enabled QGroupBox

dynamically enabled QGroupBox

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 587 Views
  • 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.
  • F Offline
    F Offline
    fender
    wrote on last edited by
    #1

    The problem is the following: there are > 50 QGroupbox, at the final stage of the program, some of them are blocked. There is also a button for resetting the result, according to which all QGroupbox goes into the state

    ui-> gb1-> setEnabled (true);
    

    How to transfer them into this state dynamically? Not to register for each

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Atleast question is not very clear to me. Let me try. What is the meaning dynamically transferring them ? What do you mean register each ?

      Do you want to call one function and state of each group box should be set ? Is this you would like to achieve ? Or is it something else ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      F 1 Reply Last reply
      0
      • dheerendraD dheerendra

        Atleast question is not very clear to me. Let me try. What is the meaning dynamically transferring them ? What do you mean register each ?

        Do you want to call one function and state of each group box should be set ? Is this you would like to achieve ? Or is it something else ?

        F Offline
        F Offline
        fender
        wrote on last edited by
        #3

        @dheerendra
        Now I prescribe for everyone

        void MainWindow::on_act_new_triggered()
        {
        ui-> gb1-> setEnabled (true);
        //-----
        a lot of code
        -----//
        ui-> gb65-> setEnabled (true);
        }
        

        This lengthens the code. I want to make it shorter

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          If these are all QGroupBoxes you can use QObject::findChildren<QGroupBox*>()

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          4
          • J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            because findchild can be a costly operation,why don't you combine @Christian-Ehrlicher 's code with a single SIGNAL in your startup process

            something like this:

            //.h
            signals:
            void enableAll(bool);
            
            //cpp constructor
            
            {
            //after ui setup
            
              for(QGroupBox *box : ui->findChildren<QGroupBox *>() )
                    connect(this, &myClass::enableAll, box, &QGroupBox::setEnabled);
            }
            
            //enable
            emit enableAll(true);
            //disable
            emit enableAll(false);
            

            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            4
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #6

              as @J-Hilk & @Christian-Ehrlicher suggested, it is findChildren is the option to go.

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              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