Using splitter with stretch factor
-
I want to display 4 Text Boxes vertically and horizontally on a window
@split1->setOrientation(Qt::Horizontal);
split1->addWidget(editor1);
split1->addWidget(split2);split2->setOrientation(Qt::Vertical);
split2->addWidget(split3);
split2->addWidget(editor2);split3->setOrientation(Qt::Horizontal);
split3->addWidget(editor3);
split3->addWidget(editor4);split1->setStretchFactor(0,1);
split1->setStretchFactor(1,1);
split1->show();@i used setStretchFactor method, i give 1 for the left big text box, and 1 for the second half(3 textboxes in a splitter)
the problem is the left text box(editor1) took just 1/3 from the window not 1/2 (like take the half of the window)
-
Hi, welcome to devnet
The key here is this quote from the "setStretchFactor":http://doc.qt.io/qt-5/qsplitter.html#setStretchFactor doc:
bq. stretch is not the effective stretch factor; the effective stretch factor is calculated by taking the initial size of the widget and multiplying it with stretch.
So imagine that at the beginning each widget gets a size of X. The left side of split1 has one widget, so it has width X. The right size has two widgets (editor3 and editor4) side by side so it gets total width of 2X. Since you apply 1 as a stretch for both of these it basically changes nothing - left side is still X and right side is 2X.
If you want to split it 50/50 you need to apply stretch value 2 to the left side so that it also gets width 2X, equalizing the weights on both sides.
-
Exactly,that's what i found it,minutes before :D
thank you