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

相关推荐
花阴偷移10 分钟前
kotlin语法(上)
android·java·开发语言·kotlin
XuanRanDev13 分钟前
【编程语言】Kotlin快速入门 - 泛型
开发语言·kotlin
普通网友14 分钟前
Android kotlin Jetpack mvvm 项目
android·开发语言·kotlin
Crogin16 分钟前
快速简单入门Kotlin——基础语法(第一天)
android·开发语言·kotlin
晨非辰16 分钟前
算法闯关日记 Episode :解锁链表「环形」迷局与「相交」奥秘
数据结构·c++·人工智能·后端·python·深度学习·神经网络
qq_3363139319 分钟前
java基础-set系列集合
java·开发语言·python
lzhdim27 分钟前
C#开发的应用启动菜单应用(普通版) - 开源研究系列文章 - 个人小作品
开发语言·c#
Kyln.Wu36 分钟前
【python实用小脚本-309】HR×Python改造面试路线规划|从手工排程到智能调度的化学反应,轻松实现路径优化
开发语言·python·面试
烤麻辣烫1 小时前
黑马程序员苍穹外卖(新手)DAY12
java·开发语言·学习·spring·intellij-idea
MM_MS1 小时前
C# 线程与并发编程完全指南:从基础到高级带详细注释版(一篇读懂)
开发语言·机器学习·计算机视觉·c#·简单工厂模式·visual studio