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

相关推荐
郑州光合科技余经理16 小时前
技术视角:海外版一站式同城生活服务平台源码解析
java·开发语言·uni-app·php·排序算法·objective-c·生活
郑州光合科技余经理16 小时前
海外版生活服务系统源码 | 外卖+跑腿一站式平台技术解析
java·开发语言·javascript·git·spring cloud·php·生活
Studying 开龙wu16 小时前
Windos 10系统安装OpenPose的CPU版本过程说明和Release版本直接使用
c++·windows
小小Fred16 小时前
Cortex-M3 LR寄存器的特殊值EXC_RETURN
java·开发语言·jvm
小小心愿家16 小时前
线程——对于锁的进一步认识
java·开发语言
曹牧16 小时前
Java: FATAL ERROR: processing of -javaagent failed
java·开发语言
橘子海全栈攻城狮16 小时前
【最新源码】基于springboot的会议室预订系统设计与实现 014
java·开发语言·前端·spring boot·后端·spring·自动化
温柔の敲代码16 小时前
从微观到宏观了解C++项目的编译
开发语言·c++
另寻沧海16 小时前
C++ Lambda表达式的隐式转换陷阱
java·c++·算法
二川bro16 小时前
字符串特性解析:Python不可变性引发的错误
android·开发语言·python