How to initialize the splitter handle position in Qt?

旧巷老猫 提交于 2020-01-14 07:37:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!