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

相关推荐
星河耀银海21 分钟前
C++开发入门——环境搭建与第一个程序
开发语言·c++·策略模式
还不秃顶的计科生25 分钟前
defaultdict讲解
开发语言·javascript·ecmascript
花归去30 分钟前
echarts 柱状图包含右侧进度
开发语言·前端·javascript
wjs202431 分钟前
Java 数组
开发语言
码农水水32 分钟前
大疆Java面试被问:TCC事务的悬挂、空回滚问题解决方案
java·开发语言·人工智能·面试·职场和发展·单元测试·php
qq_25183645737 分钟前
基于java Web 个人网站系统设计与实现
java·开发语言·数据库
Eternity∞1 小时前
基于Linux系统vim编译器情况下的C语言学习
linux·c语言·开发语言·学习·vim
周末吃鱼1 小时前
Lambda作用域
java·开发语言
故事不长丨1 小时前
C#进制转换:从基础原理到实战应用
开发语言·c#·进制转换·16进制·2进制·10进制
无言(* ̄(エ) ̄)1 小时前
进程---Linux/C语言
java·开发语言·算法