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

相关推荐
Alsn869 小时前
30.登录用户名密码 RSA 加密传输-后端为java
java·开发语言
老王熬夜敲代码9 小时前
C++的decltype
开发语言·c++·笔记
lxp1997419 小时前
PHP框架自带队列--更新中
开发语言·php
MoonBit月兔9 小时前
海外开发者实践分享:用 MoonBit 开发 SQLC 插件(其三)
java·开发语言·数据库·redis·rust·编程·moonbit
问道飞鱼9 小时前
【Rust编程知识】在 Windows 下搭建完整的 Rust 开发环境
开发语言·windows·后端·rust·开发环境
闻缺陷则喜何志丹9 小时前
【C++组合数学】P8106 [Cnoi2021] 数学练习|普及+
c++·数学·洛谷·组合数学
jllllyuz9 小时前
C# 面向对象图书管理系统
android·开发语言·c#
wuguan_9 小时前
C#文件读取
开发语言·c#·数据读写
hoiii1879 小时前
基于C#的PLC串口通信实现
开发语言·c#·plc
ALex_zry9 小时前
C++ const成员函数详解:原理、应用与最佳实践
c++