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影响,因此我并不推荐使用。

相关推荐
lly20240641 分钟前
HTML 表单
开发语言
深海潜水员3 小时前
【Python】 切割图集的小脚本
开发语言·python
钱彬 (Qian Bin)4 小时前
《使用Qt Quick从零构建AI螺丝瑕疵检测系统》——8. AI赋能(下):在Qt中部署YOLOv8模型
人工智能·qt·yolo·qml·qt quick·工业质检·螺丝瑕疵检测
Yolo566Q4 小时前
R语言与作物模型(以DSSAT模型为例)融合应用高级实战技术
开发语言·经验分享·r语言
Felven4 小时前
C. Challenging Cliffs
c语言·开发语言
Dreamsi_zh5 小时前
Python爬虫02_Requests实战网页采集器
开发语言·爬虫·python
_君落羽_6 小时前
C语言 —— 指针(4)
c语言·开发语言
weixin_448617056 小时前
疏老师-python训练营-Day30模块和库的导入
开发语言·python
望星空听星语6 小时前
C语言自定义数据类型详解(四)——联合体
c语言·开发语言
壹立科技7 小时前
Java源码构建智能名片小程序
java·开发语言·小程序