I want to initialize the splitter handle position like the following instead of in the middle. I cannot set it in the property.
How to solve this?
Thank you for your help.
I want to initialize the splitter handle position like the following instead of in the middle. I cannot set it in the property.
How to solve this?
Thank you for your help.
You can use QSplitter::setSizes
in this why to reposition the handle:
ui->splitter->setSizes(QList<int>() << 100 << 200);
You should set the horizontal stretch for the two widgets in the splitter. For instance by setting the horizontal stretch of the left widget to 1
and the right widget to 2
, the right widget gets a width 2 times the left one :
leftWidget->sizePolicy().setHorizontalStretch(1);
rightWidget->sizePolicy().setHorizontalStretch(2);
Another possible way is to use QSplitter::setSizes
.
Use QSplitter::setStretchFactor(int index, int stretch)
where index
is the position of the respective widget.