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

相关推荐
AA陈超26 分钟前
虚幻引擎5 GAS开发俯视角RPG游戏 P06-31 映射标签到属性
c++·游戏·ue5·游戏引擎·虚幻
刃神太酷啦35 分钟前
力扣校招算法通关:双指针技巧全场景拆解 —— 从数组操作到环检测的高效解题范式
java·c语言·数据结构·c++·算法·leetcode·职场和发展
wu_jing_sheng01 小时前
销售数据分析
开发语言·python
haofafa1 小时前
STL之动态数组
开发语言·c++
earthzhang20212 小时前
【2051】【例3.1】偶数
开发语言·数据结构·算法·青少年编程·图论
无敌最俊朗@2 小时前
梳理了音视频开发核心知识点
c++·音视频
专注VB编程开发20年2 小时前
.NET Reflector反编绎,如何移除DLL中的一个公开属性
开发语言·c++·c#
vxiam14xxx2 小时前
【Java Swing 项目】java 聊天系统
java·开发语言·python
落羽的落羽2 小时前
【Linux系统】C/C++的调试器gdb/cgdb,从入门到精通
linux·服务器·c语言·c++·人工智能·学习·机器学习
在下雨5992 小时前
条件变量与互斥锁复习
c++·面试