Qt-QSplitter正确设置比例

简短版本:

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

相关推荐

  1. Qt-QSplitter正确设置比例

    2023-12-07 01:20:03       35 阅读
  2. Qt: QSpliter

    2023-12-07 01:20:03       38 阅读
  3. Android Media3 ExoPlayer 如何正确设置缓存大小

    2023-12-07 01:20:03       36 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-07 01:20:03       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-07 01:20:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-07 01:20:03       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-07 01:20:03       20 阅读

热门阅读

  1. 第十二章 git

    2023-12-07 01:20:03       34 阅读
  2. 免费获取 MATLAB 代码的推荐网站

    2023-12-07 01:20:03       41 阅读
  3. python通过ssh密钥等形式链接到redis服务器

    2023-12-07 01:20:03       40 阅读
  4. 鸿蒙学习资料

    2023-12-07 01:20:03       47 阅读
  5. Android跨进程通信,RPC,IPC

    2023-12-07 01:20:03       30 阅读
  6. EOS的eosjs的演进

    2023-12-07 01:20:03       43 阅读
  7. 谨慎使用android.view.SurfaceView.setVisibility方法

    2023-12-07 01:20:03       41 阅读
  8. localForage使用 IndexedDB / WebSQL存储

    2023-12-07 01:20:03       37 阅读
  9. 【MySQL工具】my2sql-快速解析binlog

    2023-12-07 01:20:03       29 阅读