QT QSplitter设置初始比例setStretchFactor失效解决

QSplitter如下为常用 设置显示比例

1 pRightSplitter=new QSplitter(Qt::Vertical);
2 pRightSplitter->setMouseTracking(true);
3 pRightSplitter->setStretchFactor(0,8);
4 pRightSplitter->setStretchFactor(1,2);
但是由于内部有子窗口的布局时,会失效

使用下面方法设置

1 //pRightTopWidget 为子窗口1
2 QSizePolicy rightTopPolicy = pRightTopWidget->sizePolicy();
3 rightTopPolicy.setVerticalStretch(8);
4 pRightTopWidget->setSizePolicy(rightTopPolicy);
5 //pRightDownWidget 为子窗口2
6 QSizePolicy rightDownPolicy = pRightDownWidget->sizePolicy();
7 rightDownPolicy.setVerticalStretch(2);
8 pRightDownWidget->setSizePolicy(rightDownPolicy);
参考 https://blog.csdn.net/baidu_33850454/article/details/80845582
————————————————
版权声明:本文为CSDN博主「剑峰随心」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_36190978/article/details/103244087

posted @ 2021-06-03 16:53  宝贝皮  阅读(1132)  评论(0编辑  收藏  举报