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. Problem with layout & size

Problem with layout & size

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 181 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.
  • R Offline
    R Offline
    rubykhanh
    wrote on 3 Jun 2020, 14:18 last edited by
    #1
    //GLOBAL VAR
    QVBoxLayout *mainLayout = new QVBoxLayout();
    //
    
    ToDoList::~ToDoList()
    {
    }
    
    ToDoList::ToDoList(QWidget *parent)
        : QMainWindow(parent)
    {
        QWidget *centralWidget = new QWidget();
        setCentralWidget(centralWidget);
        // Layout 1b
        QHBoxLayout *bottomLayout = new QHBoxLayout();
        QTextEdit *textTask = new QTextEdit();
        QPushButton *newButton = new QPushButton("+");
        bottomLayout->addWidget(textTask,5);
        bottomLayout->addWidget(newButton,1);
        // Layout 0
        QVBoxLayout *centralLayout = new QVBoxLayout();
        centralWidget->setLayout(centralLayout);
        centralLayout->addLayout(mainLayout,10); // Layout 1a
        centralLayout->addLayout(bottomLayout,1); // Layout 1b
        //Size Policy Bottom Layout Widget
        //CONNECT
        connect(newButton, SIGNAL(clicked()), this, SLOT(newTask()));
    }
    
    void ToDoList::newTask()
    {
        QGroupBox *groupBox = new QGroupBox();
    
        QTextEdit *text = new QTextEdit();
        QPushButton *doneButton = new QPushButton("V");
        QPushButton *removeButton = new QPushButton("X");
        QHBoxLayout *groupLayout = new QHBoxLayout();
    
        groupBox->setLayout(groupLayout);
        groupLayout->addWidget(text);
        groupLayout->addWidget(doneButton);
        groupLayout->addWidget(removeButton);
    
        mainLayout->addWidget(groupBox);
        //CONNECT
        connect(removeButton, SIGNAL(clicked()), this, SLOT(delTask()));
    }
    

    My problem:

    • When i click newButton to add a groupBox, it will appear in center of mainLayout.
      If i add 2 groupBox, they will divide in 2part; 3groupBox will be 3 part.
    • If i add groupBox by using newButton more than 5 times, my app will be split out of screen.

    Help me :

    • How to set groupBox position in layout as a listwidget
    • How to add scrollbar to mainLayout.

    4.png
    2.
    2.png
    3.
    3.png

    Thanks

    1 Reply Last reply
    0
    • G Offline
      G Offline
      gde23
      wrote on 3 Jun 2020, 14:40 last edited by gde23 6 Mar 2020, 14:41
      #2

      What do you mean by "as a list widget"?

      and have you tried QScrollArea? https://doc.qt.io/qt-5/qscrollarea.html

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 3 Jun 2020, 18:31 last edited by
        #3

        Hi and welcome to devnet,

        Why do you have a global layout variable ?

        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
        1

        1/3

        3 Jun 2020, 14:18

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved