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

相关推荐
zhangren024683 小时前
PHP vs C++:从Web脚本到系统编程的终极对比
开发语言·c++·php
聆风吟º3 小时前
【C标准库】深入理解 C 语言memmove函数:安全内存拷贝的利器
c语言·开发语言·memmove·库函数
小则又沐风a3 小时前
类和对象(C++)---上
java·c++·算法
临溟夜空的繁星3 小时前
C++STL—— list
开发语言·c++·list
lsx2024063 小时前
Ruby JSON处理指南
开发语言
原来是猿3 小时前
关于【进程池阻塞 + 子进程未回收问题】
linux·服务器·c++
C澒3 小时前
PC 桌面富应用:速分客户端
前端·c++·electron·web app
深邃-3 小时前
数据结构-双向链表
c语言·开发语言·数据结构·c++·算法·链表·html5
2401_878530213 小时前
分布式任务调度系统
开发语言·c++·算法
愤豆3 小时前
06-Java语言核心-JVM原理-JVM内存区域详解
java·开发语言·jvm