dynamically enabled QGroupBox
-
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
-
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 ?
-
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
Now I prescribe for everyonevoid 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
-
If these are all QGroupBoxes you can use QObject::findChildren<QGroupBox*>()
-
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);
-
as @J-Hilk & @Christian-Ehrlicher suggested, it is findChildren is the option to go.