Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

how to create nested QGroupBox with recursion ?



  • Here is my code so far :

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        QFrame *test = new QFrame(this);
        layout = new QGridLayout;
        test->setGeometry(10,10,150,300);
        layout->addWidget(createBrightnessSettings(tr("Brightness Settings"),5,30,300,275),0,0,3,3,Qt::AlignLeft);
        test->setLayout(layout);
    }
    
    QGroupBox *MainWindow::createBrightnessSettings(const QString& name,int x,int y,int w,
                                                 int h){
    
        QGroupBox *brightnessSettings = new QGroupBox(name);
    
        if (name == "Brightness Settings"){
            brightnessSettings->setFlat(true);
            layout->addWidget(createBrightnessSettings(tr("Day Mode"),30,55,250,95),0,1,0,3,Qt::AlignLeft);
        }
        //createBrightnessSettings("Night Mode",30,170,250,95);
    
        if (name != "Brightness Settings"){
    
            //startfrom = constructLabel(settingsBackground,startfrom,"color:rgb(200,200,200);font:9pt bold Arial;",
              //                     50,68,90,25,"Start From");
        }
        brightnessSettings->setGeometry(x,y,w,h);
        return brightnessSettings;
    }
    

    This is what i want :

    https://postimg.org/image/i30xl23g5/

    thanks


  • Lifetime Qt Champion

    Hi,

    Set a QVBoxLayout in your main QGroupBox and then add the other two to that layout.


Log in to reply