Problem with layout & size
Unsolved
General and Desktop
-
//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.
2.
3.
Thanks
- When i click newButton to add a groupBox, it will appear in center of mainLayout.
-
What do you mean by "as a list widget"?
and have you tried QScrollArea? https://doc.qt.io/qt-5/qscrollarea.html
-
Hi and welcome to devnet,
Why do you have a global layout variable ?