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. Add many QLayout on a QWidget
Forum Updated to NodeBB v4.3 + New Features

Add many QLayout on a QWidget

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 644 Views 1 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.
  • M Offline
    M Offline
    Meugiwara
    wrote on last edited by Meugiwara
    #1

    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 ? :)

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

      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.

      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
      • M Offline
        M Offline
        Meugiwara
        wrote on last edited by
        #3

        I found what I wanted to do ! :D

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

        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