参考链接:

Understanding form layout mechanisms in Qt - Stack Overflow

布局用于排列和管理构成用户界面的元素。Qt 提供了许多类来自动处理布局——QHBoxLayout、QVBoxLayout、QGridLayout和QFormLayout。这些类解决了自动布局小部件的挑战,提供行为可预测的用户界面。幸运的是,使用Qt Designer排列小部件不需要布局类知识。相反,从上下文菜单中选择“水平布局” 、“在网格中布局”等选项之一。

Each Qt widget has a recommended size, known as sizeHint(). The layout manager will attempt to resize a widget to meet its size hint. In some cases, there is no need to have a different size. For example, the height of a QLineEdit is always a fixed value, depending on font size and style. In other cases, you may require the size to change, e.g., the width of a QLineEdit or the width and height of item view widgets. This is where the widget size constraints -- minimumSize and maximumSize constraints come into play. These are properties you can set in the property editor. For example, to override the default sizeHint(), simply set minimumSize and maximumSize to the same value. Alternatively, to use the current size as a size constraint value, choose one of the Size Constraint options from the widget's context menu. The layout will then ensure that those constraints are met. To control the size of your widgets via code, you can reimplement sizeHint() in your code.

每个 Qt 小部件都有一个推荐的大小,称为sizeHint()。布局管理器将尝试调整小部件的大小以满足其大小提示。在某些情况下,不需要有不同的大小。例如,QLineEdit的高度始终是一个固定值,取决于字体大小和样式。在其他情况下,您可能需要更改大小,例如QLineEdit的宽度或项目视图小部件的宽度和高度。这就是小部件大小约束—— minimumSize和maximumSize约束发挥作用的地方。这些是您可以在属性编辑器中设置的属性。例如,要覆盖默认sizeHint(),只需设置minimumSize和maximumSize为相同的值。或者,要将当前大小用作大小约束值,请从小部件的上下文菜单中选择“大小约束”选项之一。然后,布局将确保满足这些约束。要通过代码控制小部件的大小,您可以在代码中重新实现sizeHint()。

What you should be aware of regarding layouts and their size policies

  • Most Qt widgets have a size policy. This size policy tells the system how the widget should stretch or shrink. It's got from the class QSizePolicy. A size policy has both vertical and horizontal components.
  • Most widgets also have a size Hint. This size hint tells the system a widgets preferred size
  • QSizePolicy has a stretch factor to allow widgets to grow at different rates

**I am only familiar with 4 size policies**

  • fixed size policy - The size of the widget is fixed and it can't be stretched. It remains at its size hint.
  • minimum size policy - The size hint is the smallest possible size of the widget, but it _can still_ grow bigger if necessary.
  • Preferred size policy - the widget can shrink or grow bigger than its size hint.
  • expanding size policy - the widget can shrink or grow bigger than its size hint :)

You may want to ask, What is the difference between preferred and expanding? **Answer:** Imagine a form with 2 widgets, one with preferred and another with expanding. Then any extra space will be given to the widget with the expanding policy. The widget with the preferred policy will remain at its size hint.

I recommend (WARNING: am not an expert :)) you buy and read through "C++ Gui programming with QT 2nd edition". I am currently reading it and it is making a lot of sense. Look at the images and see if they make some sense.

【图解】QT 布局、 sizeHint和SizePolicy概念相关推荐

  1. Qt布局管理--部件拉伸(Stretch)原理及大小策略(sizePolicy)

    申明:本文转载自"黄邦勇帅(原名:黄勇) Qt布局管理(1):部件拉伸(Stretch)原理及大小策略(sizePolicy) 1.部件的大小策略sizePolicy.大小限制.拉伸因子(S ...

  2. qt布局嵌套_Qt的5种常用布局搭建

    Qt布局详解: 界面开发首先要对整个界面进行布局,使窗体上的所有的控件必须有一个合适的尺寸和位置.那么做出来的界面才看起来美观. 那么如何对界面进行布局呢?Qt提供了一些类负责排列窗体上的控件,主要有 ...

  3. 15.QT布局管理及示例

    Qt布局系统包含一组布局管理类,当界面变化时,布局系统会自动定位和调整窗口的大小,从而确保控件始排列整齐并确保界面可用. 所有QWidget子类都可以使用布局管理类. QWidget::setLayo ...

  4. WebKit 布局的标准和概念

    作为一个广受好评的浏览器引擎,其网页布局的质量(包括速度.效率.符合标准度等)往往是其关键,那么WebKit究竟是如何布局网页上的所有元素(包括滚动条.文字.图片.按钮.下拉框等)呢?其主要数据结构及 ...

  5. 第六章 Qt布局管理器Layout

    第六章 Qt布局管理器Layout 大家有没有发现一个现象,我们放置一个组件,给组件最原始的定位是给出这个控件的坐标和宽高值,这样Qt就知道这个组件的位置.当用户改变窗口的大小,组件还静静地呆在原来的 ...

  6. [html] 在网格布局中都有哪些概念呢?比如:网格线

    [html] 在网格布局中都有哪些概念呢?比如:网格线 容器:采用网格布局的区域项目:容器内部采用网格定位的子元素行:容器里面的水平区域列:容器里面的垂直区域单元格:行和列的交叉区域网格线:划分网格的 ...

  7. C++ Qt 05:Qt布局管理器 - 荒 木 - 博客园

    C++ Qt 05:Qt布局管理器 - 荒 木 - 博客园 下面我们以一个例子来初步了解Qt的组件定位技术,比如我们想做一个登录窗口,像下图这样,应该怎么做呢? 这还不简单嘛,在窗体上拖两个QLabe ...

  8. 【Qt】Qt布局管理器

    00. 目录 文章目录 00. 目录 01. 概述 02. 布局相关类 03. 布局图示 04. 为布局添加控件 05. 伸展因素 06. 布局中自定义控件 07. 手动布局 08. 附录 01. 概 ...

  9. QT布局以及使用QSS

    最近花了一周的时间学习了QT,学习的结果是能够使用它进行一些简单的界面开发,其实在学习的过程中发现QT的功能还是挺强大的,但因为学习的时间太短,可能它的精髓还没有能够体会到,现在想要把这段时间学习的心 ...

  10. QT 布局,控件自适应大小 自动缩放 自动布局

    有时,我们需要我们的布局或控件,随窗口变化而变化:这时就要求我们注意一下: 1. 先来说简单的布局控件自适应 首先拖动两个 verticalLayout 放到窗口: 右击空白处:右键菜单 ->布 ...

最新文章

  1. 设计所需的各种输出格式(包括整数、实数、字符串等),用一个文件名format.h把这些信息都包括到此文件内,另编写一个文件,用文件包含命令验证可以使用这些格式
  2. 搜索推荐炼丹笔记:CVR预估中的延迟反馈问题
  3. Java加载sklearn训练好的模型进行预测(无法搞定)
  4. 124_Power PivotPower BI DAX优化计算最大连续次数
  5. Spring Security Oauth2 之密码模式
  6. 局域网内两台9303 的管理vlan mac地址冲突解决方法
  7. Code First系列之视图,存储过程和异步API
  8. 数据库技术与应用知识点小结(上)
  9. app live photo_live photo动态壁纸下载-Live Photo动态壁纸app下载 苹果版v2.1-PC6苹果网...
  10. misc类设备驱动1——板载蜂鸣器驱动测试
  11. wps云盘和zotero的结合(一)
  12. 杠杆炒股平台是不是实盘?
  13. java tif合成_JAI 多图片合成TIF格式
  14. 商务办公软件应用与实践【2】
  15. 10G整数文件需找中位数
  16. elementUI tooltip箭头样式(表格自定义)
  17. cmd package install-create -r -t -S returns error
  18. kettle-创建资源库
  19. 基于python的智能家居_基于Python的智能家居自动化测试脚本设计及实现
  20. 订单搜索分页失效的教训:怠惰必受惩罚

热门文章

  1. Luogu5816 [CQOI2010]内部白点
  2. 【C++/Python 双语言实现】Luogu1196 银河英雄传说 + Python函数的定义与调用
  3. Linux下安装zabbix-agent详解
  4. c语言qsort函数对结构体的一级排序,sort和qsort函数对结构体的二级排序
  5. python创建数据集_python 生成环形人工数据集
  6. 防火墙阻止tftp_再谈突破TCP-IP过滤/防火墙进入内网(icmp篇)
  7. calabash android教程,Calabash Android 使用教程 (二)
  8. 数组、字符串、集合的相互转换
  9. cmw500 lte非信令测试_买CMW500,信令与非信令的含义?功能?
  10. ajax jsonp不触发后台_JsonP