转自:https://blog.csdn.net/u013928315/article/details/78123573

一、QGridLayout属性介绍

1、QGridlayout以方格的形式管理窗口部件,先看QGridLayout的属性,如下图

2、各个参数的介绍

layoutLeftMargin ...至layoutBottomMargin在ui_MainWindow.h中自动生成的代码是:

gridLayout->setContentsMargins(20, 10, 10, 10);

学过CSS都知道,这是设置一个元素所有外边距的宽度,或者设置各边上外边距的宽度

On most platforms, the margin is 11 pixels in all directions.

HorizontalSpacing...至VerticalSpacing在ui_MainWindow.h中自动生成的代码是:

gridLayout->setHorizontalSpacing(6);

gridLayout->setVerticalSpacing(6);

这是设置两个控件之间的水平和竖直距离

LayoutRowStretch在ui_MainWindow.h中自动生成的代码是:

gridLayout->setRowStretch(0, 1);

gridLayout->setRowStretch(1, 1);

gridLayout->setRowStretch(2, 1);

表示在第0行、第1行、第2行 在竖直方向的空间比例分配,大家稍微改一下参数就能看出来效果

LayoutColumnStretch在ui_MainWindow.h中自动生成的代码是:

gridLayout->setColumnStretch(1, 1);

表示设置第0列、第1列两者在水平方向的空间比例分配。

LayoutRowMinimumHeight在ui_MainWindow.h中自动生成的代码是:

gridLayout->setRowMinimumHeight(0, 1);

gridLayout->setRowMinimumHeight(1, 2);

gridLayout->setRowMinimumHeight(2, 3);

表示在第0行、第1行、第2行的最小高度是1pixels,2pixels,3pixels

LayoutColumnMinimumWidth在ui_MainWindow.h中自动生成的代码是:

gridLayout->setColumnMinimumWidth(0, 4);

gridLayout->setColumnMinimumWidth(1, 5);

表示设置第0列、第1列的最小宽度是4pixels、5pixels

LayoutSizeConstraint在ui_MainWindow.h中自动生成的代码是:

gridLayout->setSizeConstraint(QLayout::SetDefaultConstraint);

This property holds the resize mode of the layout.看下表

enum QLayout::SizeConstraint

The possible values are:

Constant Value Description

QLayout::SetDefaultConstraint 0 The main widget's minimum size is set to minimumSize(), unless the widget already has a minimum size.
QLayout::SetFixedSize 3 The main widget's size is set to sizeHint(); it cannot be resized at all.
QLayout::SetMinimumSize 2 The main widget's minimum size is set to minimumSize(); it cannot be smaller.
QLayout::SetMaximumSize 4 The main widget's maximum size is set to maximumSize(); it cannot be larger.
QLayout::SetMinAndMaxSize 5 The main widget's minimum size is set to minimumSize() and its maximum size is set tomaximumSize().
QLayout::SetNoConstraint 1

The widget is not constrained.

QFormLayout属性介绍

1、QFormLayout类管理输入型控件和它的label组成的那些form表格,包括它的界面参数如下图

2、界面中对应的代码如下表,

Cpp代码   

  1. formLayout = new QFormLayout(widget1);
  2. formLayout->setSpacing(6);
  3. formLayout->setContentsMargins(11, 11, 11, 11);
  4. formLayout->setObjectName(QString::fromUtf8("formLayout"));
  5. formLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
  6. formLayout->setRowWrapPolicy(QFormLayout::DontWrapRows);
  7. formLayout->setContentsMargins(0, 0, 0, 0);
  8. label_4 = new QLabel(widget1);
  9. label_4->setObjectName(QString::fromUtf8("label_4"));
  10. formLayout->setWidget(0, QFormLayout::LabelRole, label_4);
  11. lineEdit = new QLineEdit(widget1);
  12. lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
  13. formLayout->setWidget(0, QFormLayout::FieldRole, lineEdit);
  14. label_5 = new QLabel(widget1);
  15. label_5->setObjectName(QString::fromUtf8("label_5"));
  16. formLayout->setWidget(1, QFormLayout::LabelRole, label_5);
  17. comboBox = new QComboBox(widget1);
  18. comboBox->setObjectName(QString::fromUtf8("comboBox"));
  19. formLayout->setWidget(1, QFormLayout::FieldRole, comboBox);

3、其中值得一说的是:LayoutFieldGrowthPolicy属性

enum QFormLayout::FieldGrowthPolicy

This enum specifies the different policies that can be used to control the way in which the form's fields grow.

Constant Value Description

QFormLayout::FieldsStayAtSizeHint 0 The fields never grow beyond their effective size hint. This is the default forQMacStyle.
QFormLayout::ExpandingFieldsGrow 1 Fields with an horizontal size policy of Expanding or MinimumExpanding will grow to fill the available space. The other fields will not grow beyond their effective size hint. This is the default policy for Plastique.
QFormLayout::AllNonFixedFieldsGrow 2 All fields with a size policy that allows them to grow will grow to fill the available space. This is the default policy for most styles.

4、还有一个属性值得说:LayoutRowWrapPolicy

This property holds the way in which the form's rows wrap.

//这个属性设置了表格如何排版各个元素

If you want to display each label above its associated field (instead of next to it), set this property to WrapAllRows.

//如果你想把每个标签放在相关字段的上方,而不是和它相邻,就设置这个属性值为WrapAllRows。

enum QFormLayout::RowWrapPolicy

This enum specifies the different policies that can be used to control the way in which the form's rows wrap.

Constant Value Description

QFormLayout::DontWrapRows 0 Fields are always laid out next to their label. This is the default policy for all styles except Qt Extended styles and QS60Style.
QFormLayout::WrapLongRows 1 Labels are given enough horizontal space to fit the widest label, and the rest of the space is given to the fields. If the minimum size of a field pair is wider than the available space, the field is wrapped to the next line. This is the default policy for Qt Extended styles and andQS60Style.
QFormLayout::WrapAllRows 2 Fields are always laid out below their label.

【转】QGridLayout 详解相关推荐

  1. QT:常用函数详解--常用操作记录(个人笔记)

    QT:常用函数详解(个人笔记) PS:一下内容个人笔记,要求自己看懂,随笔,阅读体验会很差很差! Qt setContentsMargins()函数 函数原型:void QLayout::setCon ...

  2. 第15.12节PyQt(Python+Qt)入门学习:可视化设计界面组件布局详解

    一.引言 在Qt Designer中,在左边部件栏的提供了界面布局相关部件,如图: 可以看到共包含有四种布局部件,分别是垂直布局(Vertical Layout).水平布局(Horizontal La ...

  3. Qt之布局设置setLayout详解-源码剖析(下)

    一.简述 大家好,我是前行中的小猪,今天呢给大家继续上一篇Qt之布局设置setLayout详解(上)之后的内容,再给大家进行一下拓展. 1.1 setLayout源码剖析 上篇我们说到如何清空部件上的 ...

  4. 从命令行到IDE,版本管理工具Git详解(远程仓库创建+命令行讲解+IDEA集成使用)

    首先,Git已经并不只是GitHub,而是所有基于Git的平台,只要在你的电脑上面下载了Git,你就可以通过Git去管理"基于Git的平台"上的代码,常用的平台有GitHub.Gi ...

  5. JVM年轻代,老年代,永久代详解​​​​​​​

    秉承不重复造轮子的原则,查看印象笔记分享连接↓↓↓↓ 传送门:JVM年轻代,老年代,永久代详解 速读摘要 最近被问到了这个问题,解释的不是很清晰,有一些概念略微模糊,在此进行整理和记录,分享给大家.在 ...

  6. docker常用命令详解

    docker常用命令详解 本文只记录docker命令在大部分情境下的使用,如果想了解每一个选项的细节,请参考官方文档,这里只作为自己以后的备忘记录下来. 根据自己的理解,总的来说分为以下几种: Doc ...

  7. 通俗易懂word2vec详解词嵌入-深度学习

    https://blog.csdn.net/just_so_so_fnc/article/details/103304995 skip-gram 原理没看完 https://blog.csdn.net ...

  8. 深度学习优化函数详解(5)-- Nesterov accelerated gradient (NAG) 优化算法

    深度学习优化函数详解系列目录 深度学习优化函数详解(0)– 线性回归问题 深度学习优化函数详解(1)– Gradient Descent 梯度下降法 深度学习优化函数详解(2)– SGD 随机梯度下降 ...

  9. CUDA之nvidia-smi命令详解---gpu

    nvidia-smi是用来查看GPU使用情况的.我常用这个命令判断哪几块GPU空闲,但是最近的GPU使用状态让我很困惑,于是把nvidia-smi命令显示的GPU使用表中各个内容的具体含义解释一下. ...

最新文章

  1. Python学习【第6篇】:Python之文件操作
  2. 计算机一级考试考网络什么,计算机一级考试内容 一级考试难不难
  3. java springmvc权限校验_详解Spring MVC使用Filter实现登录及权限验证判断
  4. C语言 void 指针 - C语言零基础入门教程
  5. 剑指offer——10.斐波那契数列
  6. 线程并发与进程并发各有什么you_【白话计算机基础】并发与并行,进程、线程与协程, 同步与异步,阻塞与非阻塞...
  7. centos7安装java(多种方式)
  8. Adobe Photoshop CS6软件安装教程
  9. 修改最新版谷歌浏览器编码方式
  10. mysql的七种查询命令_MySQL数据库查询指令大全
  11. 湖北商贸学院计算机二级领取,湖北商贸学院教务管理系统入口http://jw.hbc.edu.cn/...
  12. sapi/cgi/php-cgi,sapi/cgi/php-cgi
  13. cocos2dx layer理解
  14. Android系统根目录下的各个文件夹的作用与区别介绍
  15. 超参数优化:网格搜索法
  16. linux补丁rt ck pf zen,Linux 内核社区补丁对比
  17. 数据库学习 (一):数据库系统概述
  18. nginx配置https访问 生成ssl自签名证书,浏览器直接访问
  19. windows 向 iPad导入文件
  20. 自然语言处理(六)图的随机游走模型与噪声信道模型与条件随机场

热门文章

  1. Hive分析窗口函数 NTILE,ROW_NUMBER,RANK,DENSE_RANK
  2. session与cokkie区别
  3. 关于算法模板和规范的说明
  4. 2-jQuery - AJAX load() 方法【进阶篇】
  5. 根据select不同的选项实现相应input框添加项的显示
  6. ActiveReports 报表控件官方中文入门教程 (2)-创建、数据源、浏览以及发布
  7. 容斥原理的二进制实现模版
  8. 随机交换检验数据挖掘结果-assessing data mining result via swap randomization
  9. 泛型实现List(ListT)排序
  10. [密码学基础][信息安全][每个信息安全博士生应该知道的52件事][Bristol Cryptography][第11篇]DLP、CDH和DDH问题是什么?