Qt-QSplitter正确设置比例

简短版本:

cpp 复制代码
splitter->setSizes({1000, 2000}); // 这个值至少跟像素值设置的一样大,或者更大,例如x10倍

详细版本:

setSizes 官方介绍如下:

Sets the child widgets' respective sizes to the values given in the list.

If the splitter is horizontal, the values set the width of each widget in pixels, from left to right. If the splitter is vertical, the height of each widget is set, from top to bottom.

Extra values in the list are ignored. If list contains too few values, the result is undefined, but the program will still be well-behaved.
The overall size of the splitter widget is not affected. Instead, any additional/missing space is distributed amongst the widgets according to the relative weight of the sizes.

If you specify a size of 0, the widget will be invisible. The size policies of the widgets are preserved. That is, a value smaller than the minimal size hint of the respective widget will be replaced by the value of the hint.

重点如下:

splitter大小不会变化,比设置的值多的和少的空间将会按照sizes之间的比例分配

size policy保留,且widget至少有minmum size的最小值大小

网上说的setStetch方法对我不管用(左边使用QTreeWidget,右边是QWidget),并且会受到sizePolicy和minimum size影响,因此我并不推荐使用。

相关推荐
jllllyuz7 小时前
matlab使用B样条进行曲线曲面拟合
开发语言·matlab
农夫山泉2号7 小时前
【c++】——c++编译的so中函数有额外的字符
java·服务器·c++
ku_code_ku7 小时前
python bert_score使用本地模型的方法
开发语言·python·bert
小马哥编程7 小时前
【软考架构】滑动窗口限流算法的原理是什么?
java·开发语言·架构
水煎包V:YEDIYYDS8887 小时前
QT QML 实现的摇杆按钮,类似王者荣耀 左边方向导航键
qt·qml·摇杆按钮·导航键
仰泳的熊猫7 小时前
1077 Kuchiguse
数据结构·c++·算法·pat考试
云栖梦泽7 小时前
鸿蒙数据持久化实战:构建本地存储与云同步系统
开发语言·鸿蒙系统
wjs20248 小时前
《Ionic 侧栏菜单》
开发语言
祁思妙想8 小时前
linux常用命令
开发语言·python
IMPYLH8 小时前
Lua 的 IO (输入/输出)模块
开发语言·笔记·后端·lua