问题
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.
回答1:
You can use QSplitter::setSizes
in this why to reposition the handle:
ui->splitter->setSizes(QList<int>() << 100 << 200);
回答2:
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
.
回答3:
Use QSplitter::setStretchFactor(int index, int stretch)
where index
is the position of the respective widget.
来源:https://stackoverflow.com/questions/25063003/how-to-initialize-the-splitter-handle-position-in-qt