Reputation: 2665
I am trying to make a layout where once the first line of it is populated by widgets, it starts adding new ones to the next line. QGridLayout
sort of looks like what I need, however it has symmetry and I don't want symmetry, cause the widgets are all different sizes. QVBoxLayout
works perfectly for one line, but making it multi-line would be impossibly hard.
Upvotes: 1
Views: 1576
Reputation: 1087
If I understand your goals right, I think using a Flow Layout rather than hacking a QGridLayout would be simpler and probably nicer looking; it just so happens one of the Qt examples is just such a thing (code appears to be BSD licensed, see bottom of page): http://doc.qt.io/qt-5/qtwidgets-layouts-flowlayout-example.html
Upvotes: 1
Reputation: 1298
You can use QGridLayout and still define different sizes for each widget by manipulating the rowspan and colspan parameters in the addWidget call.
For example suppose I have a QTextEdit, a QPushButton and a QLabel that I want to lay out horizontally next to each other. The QTextEdit is four times the width of the QPushButton which is half the width of the QLabel.
I can represent these sizes in a QGridLayout as below:
gridlayout->addWidget(textedit, 0 /*row*/, 0 /*col*/, 1 /*rowSpan*/, 4 /*colSpan*/, 0);
glayout_->addWidget(button, , 0, 4, 1, 0);
gridlayout->addWidget(label, 0, 5, 1, 2, 0);
Upvotes: 1