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

相关推荐
雨季66620 分钟前
构建 OpenHarmony 简易文字行数统计器:用字符串分割实现纯文本结构感知
开发语言·前端·javascript·flutter·ui·dart
雨季66623 分钟前
Flutter 三端应用实战:OpenHarmony 简易倒序文本查看器开发指南
开发语言·javascript·flutter·ui
进击的小头41 分钟前
行为型模式:策略模式的C语言实战指南
c语言·开发语言·策略模式
Aevget1 小时前
MFC扩展库BCGControlBar Pro v37.2新版亮点:控件功能进一步升级
c++·mfc·界面控件
天马37981 小时前
Canvas 倾斜矩形绘制波浪效果
开发语言·前端·javascript
四维碎片1 小时前
QSettings + INI 笔记
笔记·qt·算法
Tansmjs1 小时前
C++与GPU计算(CUDA)
开发语言·c++·算法
qx091 小时前
esm模块与commonjs模块相互调用的方法
开发语言·前端·javascript
Suchadar1 小时前
if判断语句——Python
开发语言·python
莫问前路漫漫2 小时前
WinMerge v2.16.41 中文绿色版深度解析:文件对比与合并的全能工具
java·开发语言·python·jdk·ai编程