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

相关推荐
一叶落43815 小时前
LeetCode 149. 直线上最多的点数(C语言详解 | 斜率 + 最大共线点)
数据结构·c++·算法·leetcode
仰泳的熊猫15 小时前
题目2267:蓝桥杯2016年第七届真题-取球博弈
数据结构·c++·算法·蓝桥杯·深度优先·图论
大尚来也15 小时前
超越“传参”:HTTP GET与POST的深度辨析与场景选型指南
开发语言
大鹏说大话15 小时前
破局与重构:微服务架构的演进之路、核心挑战与基石组件
开发语言
程序员敲代码吗15 小时前
进程与线程:操作系统中的核心组件
java·开发语言
Java面试题总结15 小时前
java面试题及答案(基础题122道)
java·开发语言·jvm·spring·spring cloud·golang·java-ee
Genevieve_xiao15 小时前
【差分】差分的理解与基础题型总结
数据结构·c++·算法
Cg1362691597415 小时前
JS-对象-array数组
开发语言·前端·javascript
智者知已应修善业15 小时前
【无序数组指针交换2则】2024-10-28
c语言·数据结构·c++·经验分享·笔记·算法
liulilittle15 小时前
MIMT审计技术:TLS信任链的脆弱性与资本主义商业逻辑下的必然
网络·c++·tcp/ip·tls·mimt