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

相关推荐
2301_7890156215 小时前
C++:模板进阶
c语言·开发语言·汇编·c++
互亿无线明明15 小时前
在 Go 项目中集成国际短信能力:从接口调试到生产环境的最佳实践
开发语言·windows·git·后端·golang·pycharm·eclipse
噔噔噔噔@15 小时前
详细介绍Python+Pytest+BDD+Playwright,用FSM打造高效测试框架
开发语言·python·pytest
Ivy_belief15 小时前
Linux:设置和获取单片机gpio引脚和key值
linux·arm开发·qt·gpio·event事件
海上彼尚15 小时前
Go之路 - 5.go的流程控制
开发语言·后端·golang
sg_knight15 小时前
什么是设计模式?为什么 Python 也需要设计模式
开发语言·python·设计模式
脾气有点小暴15 小时前
UniApp实现刷新当前页面
开发语言·前端·javascript·vue.js·uni-app
是小胡嘛15 小时前
仿Muduo高并发服务器之Buffer模块
开发语言·c++·算法
im_AMBER15 小时前
Leetcode 75 数对和 | 存在重复元素 II
c++·笔记·学习·算法·leetcode
ZXF_H15 小时前
C/C++ OpenSSL自适应格式解析证书二进制字节流
c语言·开发语言·c++·openssl