Initial Position QSplitter
-
Hi,
Do you take into account the minimal size of the widgets as well as their size policies ? From the doc, they will be respected.
-
-
What value does
height()
return ? -
It returns the same value 30 independent of the type of the containing widget that may be of a different type (which is what I would expect). Not sure however whether 30 is rather small.
What is actually not clear to me for the QSplitter::setSizes function is whether the given size values are considered as relative to each other or whether they are considered as absolute values.
-
You should rather use sizeHint. I'm guessing that you are calling that from the constructor. At that time, the widget has not yet any idea of its final size when shown. All the more since you put your widgets in a "floating" QSplitter. Floating because it doesn't seem to be in any layout or QMainWindow.
Since 30 is likely less than the minimal size of your other widgets. setSize will use their sizeHint to try to come up with something suitable.
-
Thanks to your remark @SGaist on the widget not yet having an idea of its final size at its construction, I have been able to solve it as indicated below. I should call setSize after setting the layout of the widget it is part of. I also applied your hint on using sizeHint.
QWidget *TopWidget = new QWidget(this); TopWidget->setLayout(Top); Splitter = new QSplitter(Qt::Vertical); Splitter->addWidget(TopWidget); Splitter->addWidget(Behavior); Splitter->setCollapsible(0, false); Splitter->setCollapsible(1, false); QVBoxLayout *Main = new QVBoxLayout; Main->addWidget(Splitter); setLayout(Main); QList<int> Sizes; Sizes.append(0.5 * sizeHint().height()); Sizes.append(0.5 * sizeHint().height()); Splitter->setSizes(Sizes);
The approach of using setStrechFactor instead of setSize does not work...
-
Silly question but did you remove the call to setSize when using setStretchFactor ?
-
No, no, that was right.