其他分享
首页 > 其他分享> > QT QSplitter设置初始比例setStretchFactor失效解决

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

标签:QT,setStretchFactor,rightDownPolicy,QSplitter,pRightDownWidget,pRightSplitter,ri
来源: https://www.cnblogs.com/bob-jianfeng/p/11908609.html