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

相关推荐
蜡笔弄丢了小新几秒前
E: The package APP needs to be reinstalled, but I can‘t find an archive for it.
qt
钢板兽3 分钟前
Java常见的23种设计模式
java·开发语言·设计模式
Pasregret6 分钟前
01-JVM 内存模型与 GC 原理
java·开发语言·jvm·后端
钢铁男儿12 分钟前
Python 字典和集合(字典推导)
开发语言·python
浩浩乎@22 分钟前
windows+cmake+vscode+NDK远程调试安卓端C++项目
c++·vscode
学习2年半27 分钟前
equals() 和 hashCode()
java·开发语言·jvm
多云的夏天32 分钟前
C++-Mongoose(2)-https-server-openssl
开发语言·c++·https
孙同学_35 分钟前
【C++】stack和queue
开发语言·c++
起个破名想半天了1 小时前
Pyside6使用QtWebEngine实现GUI嵌入网页内容
开发语言·python
牛奶咖啡.8541 小时前
树和图论(详细整理,简单易懂!)
数据结构·c++·算法·深度优先·图论