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

相关推荐
chao1898445 小时前
基于 SPEA2 的多目标优化算法 MATLAB 实现
开发语言·算法·matlab
赏金术士5 小时前
Kotlin 习题集 · 高级篇
android·开发语言·kotlin
楼兰公子6 小时前
buildroot 在编译rust时裁剪平台类型数量的方法
开发语言·后端·rust
知识领航员6 小时前
蘑兔AI音乐深度实测:功能拆解、实测表现与适用场景
java·c语言·c++·人工智能·python·算法·github
吴声子夜歌6 小时前
Go——并发编程
开发语言·后端·golang
ooseabiscuit7 小时前
Laravel4.x:现代PHP框架的奠基之作
java·开发语言·php
c1s2d3n4cs7 小时前
Qt模仿nlohmann::json进行序列化和反序列化
开发语言·qt·json
AiTop1008 小时前
Claude Code 推出 Agent View:命令行编程正式进入“多线程并发“时代
开发语言·人工智能·ai·aigc
jf加菲猫8 小时前
第21章 Qt WebEngine
开发语言·c++·qt·ui
码农-阿杰9 小时前
深入理解 synchronized 底层实现:从 HotSpot C++ 源码看对象锁与 Monitor 机制
开发语言·c++·