I am currently starting to play around with qt layouts, and I run into a problem: For example if I use a VBoxLayout
, then every item gets the same space as the others, eg they separate the space equally. But in my case I want to have one item with 90 % space and the other one with 10% space. I already found out that I can use sizePolicy
for that, but I have not found this if I want to resize layouts in layouts (eg if I set a layout and an item in another layout). Thus: how can I resize layouts?
Specifically for this reason you can use QBoxLayout::setStretchFactor
.
This method sets how much space should accomodate each widget or layout in coefficients.
You can pass whether QWidget
or QLayout
there.
You can read more about stretch factors here .
EDIT: Here is a simple example which illustrates how it works:
QFrame* f1 = new QFrame;
f1->setFrameStyle(QFrame::Box);
QFrame* f2 = new QFrame;
f2->setFrameStyle(QFrame::Box);
QWidget* w = new QWidget;
QVBoxLayout* l = new QVBoxLayout;
w->setLayout(l);
l->addWidget(f1);
l->addWidget(f2);
l->setStretchFactor(f1, 1);
l->setStretchFactor(f2, 2);
w->show();
Result:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.