Add many QLayout on a QWidget



  • Hello !

    I'm working on a simple program I searched on the Internet if I can add many QLayout on a QWidget, but it's impossible ! So, my question is : does it exist an other way to proceed ? Below, you can find my code and a picture of what I want to do :

    #include "main.h"
     
    int     main(int argc, char **argv)
    {
        QApplication    program(argc, argv);
        QWidget         window;
     
        window.setWindowTitle("Launch private server Flyff");
        window.setFixedSize(600, 300);
     
        /* ******************** AccountServer ******************** */
        QHBoxLayout     accountlayout;
        QLabel          accountlabel("AccountServer");
        QLineEdit       accountlineedit;
        QPushButton     accountbuttonselect("Select");
        QPushButton     accountbuttonlaunch("Launch");
        QPushButton     accountbuttonstop("Stop");
     
        accountlayout.addWidget(&accountlabel);
        accountlayout.addWidget(&accountlineedit);
        accountlayout.addWidget(&accountbuttonselect);
        accountlayout.addWidget(&accountbuttonlaunch);
        accountlayout.addWidget(&accountbuttonstop);
        window.setLayout(&accountlayout);
        /* ******************** AccountServer ******************** */
     
        /* ******************** DatabaseServer ******************** */
        QHBoxLayout     databaselayout;
        QLabel          databaselabel("DatabaseServer");
        QLineEdit       databaselineedit;
        QPushButton     databasebuttonselect("Select");
        QPushButton     databasebuttonlaunch("Launch");
        QPushButton     databasebuttonstop("Stop");
     
        databaselayout.addWidget(&databaselabel);
        databaselayout.addWidget(&databaselineedit);
        databaselayout.addWidget(&databasebuttonselect);
        databaselayout.addWidget(&databasebuttonlaunch);
        databaselayout.addWidget(&databasebuttonstop);
        window.setLayout(&databaselayout);
        /* ******************** DatabaseServer ******************** */
     
        window.show();
        return program.exec();
    }
    

    My first step is :

    alt text

    I want that the "section DatabaseServer" comes under the "section AccountServer". How can I do ? :)


  • Lifetime Qt Champion

    Hi,

    Sure you can. You can only set one layout on QWidget, but you can then add other layouts to that one. So basically set a QVBoxLayout on your widget and then add accountLayout and databaseLayout to that layout.



  • I found what I wanted to do ! :D

    I created a QVBoxLayout and used addLayout to QHBoxLayout's from QVBoxLayout.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.