简体   繁体   English

如何在Qt中初始化分离器手柄位置?

[英]How to initialize the splitter handle position in Qt?

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 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 : 例如,通过将左侧窗口小部件的水平拉伸设置为1 ,将右侧窗口小部件设置为2 ,右侧窗口小部件的宽度为左侧窗口小部件的2倍:

leftWidget->sizePolicy().setHorizontalStretch(1);
rightWidget->sizePolicy().setHorizontalStretch(2); 

Another possible way is to use QSplitter::setSizes . 另一种可能的方法是使用QSplitter::setSizes

你可以使用QSplitter::setSizes来重新定位句柄:

ui->splitter->setSizes(QList<int>() << 100 << 200);

使用QSplitter::setStretchFactor(int index, int stretch) ,其中index是相应小部件的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM