【转】QGridLayout 详解

转自: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::SetDefaultConstraint0The main widget's minimum size is set to minimumSize(), unless the widget already has a minimum size.
QLayout::SetFixedSize3The main widget's size is set to sizeHint(); it cannot be resized at all.
QLayout::SetMinimumSize2The main widget's minimum size is set to minimumSize(); it cannot be smaller.
QLayout::SetMaximumSize4The main widget's maximum size is set to maximumSize(); it cannot be larger.
QLayout::SetMinAndMaxSize5The main widget's minimum size is set to minimumSize() and its maximum size is set tomaximumSize().
QLayout::SetNoConstraint1

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.   
  11.         formLayout->setWidget(0, QFormLayout::LabelRole, label_4);  
  12.   
  13.         lineEdit = new QLineEdit(widget1);  
  14.         lineEdit->setObjectName(QString::fromUtf8("lineEdit"));  
  15.   
  16.         formLayout->setWidget(0, QFormLayout::FieldRole, lineEdit);  
  17.   
  18.         label_5 = new QLabel(widget1);  
  19.         label_5->setObjectName(QString::fromUtf8("label_5"));  
  20.   
  21.         formLayout->setWidget(1, QFormLayout::LabelRole, label_5);  
  22.   
  23.         comboBox = new QComboBox(widget1);  
  24.         comboBox->setObjectName(QString::fromUtf8("comboBox"));  
  25.   
  26.         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::FieldsStayAtSizeHint0The fields never grow beyond their effective size hint. This is the default forQMacStyle.
QFormLayout::ExpandingFieldsGrow1Fields 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::AllNonFixedFieldsGrow2All 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::DontWrapRows0Fields are always laid out next to their label. This is the default policy for all styles except Qt Extended styles and QS60Style.
QFormLayout::WrapLongRows1Labels 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::WrapAllRows2Fields are always laid out below their label.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/436208.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

php网站评论模块怎么写,模块内容评论循环

一、作用用于循环查询模块评论数据(支持分页查询)二、语法{commentmodule模块名称....}{/comment}三、参数介绍(红色表示必填参数,蓝色表示系统默认参数)参数介绍module用来查询模块的评论,例如新闻模块,填写newssite站点id,默认当…

什么是LINQ?

什么是LINQ? LINQ,语言级集成查询(Language INtegrated Query)经过了最近 20 年,面向对象编程技术( object-oriented (OO) programming technologies )在工业领域的应用已经进入了一个稳定的发展阶段。程序…

宋体(Simsun)和新宋体(NSimsun)的区别

我们平常说的宋体(Simsun)全称为中易宋体,它和新宋体(NSimsun)是由北京中易中标电子信息技术有限公司制作并持有版权的两个TrueType 字体。自从微软向中易购买了这套字型后,它便成为了简体中文使用者最熟悉…

商业计划书最好就是十页篇幅

第一页是市场介绍;第二页分析市场问题;第三页写解决问题的方式;第四页调研市场;第五页分析竞争对手;第六页介绍核心竞争力;第七页写盈利模式;第八页写近期目标;第九页写资金预算&…

java import 出错,Eclipse的java代码出错:The import XXXX cannot be resolved

折腾Eclipse时,经常会遇到这种情况:缺少某个库,找到之后,需要将该库,jar包,加入到当前项目,使得代码中的import xxx得以正常导入。【如何在Eclipse中导入/添加(外部的)库/jar包】基本思路&#…

Platform Builder实践之配置文件

这篇文章主要讲解PB的配置文件。从用途方面分析,PB包含两种配置文件。分别是源码配置文件和镜像配置文件。下面分别讲解这两种配置文件。 一、源码配置文件:源码配置文件用于编译源码时使用。这里的源码是指Windows CE公开的源码,如驱动程序、…

【转】itk、vtk、qt 显示dicom 数据

转自:https://blog.csdn.net/Zzhouzhou237/article/details/107199076/ 以下代码实现了itk读取dicom数据,转换为vtkData,然后用Qt显示。 1、Qt Designer 搭建界面,QVTKOpenGLNativeWidget 是vtk的一个类,连接qt与vtk…

页面执行顺序

今天写绑定下拉用户控件中,下拉列表的数据时,发现竟然后台的数据为空. 今天才有点明白页面的执行顺序。 转载于:https://www.cnblogs.com/jskingli/archive/2008/05/09/1190176.html

Windows CE创建桌面快捷方式

在使用Platform Builder创建Windows CE系统的内核映入文件NK.bin时, 创建一个桌面快捷方式的步骤如下:1、创建一个快捷方式文件Test.lnk,格式如下: 17#/Windows/Test.exe 其 中,17表示#后面有多少个字符 2、将此文件拷…

php 国密,PHP实现国密算法SM4

1.SM4算法实现class SM4{const SM4_CK [0x00070e15, 0x1c232a31, 0x383f464d, 0x545b6269,0x70777e85, 0x8c939aa1, 0xa8afb6bd, 0xc4cbd2d9,0xe0e7eef5, 0xfc030a11, 0x181f262d, 0x343b4249,0x50575e65, 0x6c737a81, 0x888f969d, 0xa4abb2b9,0xc0c7ced5, 0xdce3eaf1, 0xf8ff…

【转】WM_MESSAGE、WM_COMMAND、WM_NOTIFY等消息有什么不同

转自:https://blog.csdn.net/newstarao/article/details/3775690 WM_MESSAGE是最普通的WINDOWS消息,对于这种类型的消息没什么好说的。那WM_COMMAND和WM_NOTIFY消息都是WINDOWS CONTROL给它的父窗体发的消息,那这两种消息有什么不同呢&#…

修改了WINCE自带的驱动程序后如何编译

修改了WINCE自带的驱动程序后如何编译?如果是自己开发的驱动程序如何编译? 1、分为IDE方式和命令行方式。 IDE 方式的编译很简单,以PB5.0为例,打开定制内核的工程,在左边的“workspace”—“FileView”中找到你已经修…

Properties 类的使用

Properties 类已不是新东西了,它在 Java 编程的早期就有了,并且几乎没有什么变化。J2SE 的 Tiger 版本增强了这个类,不仅可以用它在单独一行中指定用等号分隔的多个键-值对,还可以用XML 文件装载和保存这些键-值对。在 驯服 Tiger…

php 9000 端口没起来,ubuntu fpm-php 未监听9000端口问题

今天搞一台新的ubuntu服务器;配置好nginx后 死活解析不了php文件,反复修改配置文件未果;于是怀疑fpm-php,遂 :netstat -ant |grep 9000惊奇的发现9000端口竟然没有被占用,可是php5-fpm服务已经开启了;于是查…

【转】控件通知消息

转自:https://blog.csdn.net/kinghzking/article/details/6180956 2008年04月06日 星期日 00:09 控件通知消息有很多种,但是有一种是很常用,但是又不是很容易掌握的,那就是WM_NOTIFY,我试着对此做一下比较全面的论述…

python 装饰器 java,python之各种装饰器的使用

"""装饰器,带参数的装饰器,类的装饰器判断是否为可迭代的from collections import Iterableprint(isinstance([1,2,3],Iterable))"""# 1、简单的装饰器def debug(func):def wrap():print(fdebug:func name is {func.__nam…

WINCE 网卡控制

最近在搞wifi上网,看了些这方面的资料,稍微总结点东西:) DeviceIoControl和底层通信: 方法1 :把第二个参数设为IOCTL_NDIS_REBIND_ADAPTER。 方法2 :把第二个参数设为IOCTL_NDIS_UNBIND_ADAPTER…

【转】调用约定__cdecl、__stdcall和__fastcall的区别

什么是调用约定 函数的调用约定,顾名思义就是对函数调用的一个约束和规定(规范),描述了函数参数是怎么传递和由谁清除堆栈的。它决定以下内容:(1)函数参数的压栈顺序,(2)由调用者还是被调用者把参数弹出栈,(3)以及产生…

WCF从理论到实践(14):WCF解决方案模板 (转)

WCF从理论到实践(14):WCF解决方案模板 正所谓磨刀不误砍柴工,虽然VS2008为我们提供了WCFServiceLibrary项目模板,但在实际开发的时候,我们通常更喜欢按照自己的方式来建立WCF项目,通常情况下,我们将服务契约(通常是接口)数据契约,消息契约等契约单独作为一个项目,而将服务的实现…

java面试宝典 多线程,《java面试宝典》之java多线程面试题

1:什么是线程?轻量级的进程2:线程的三个部分是?处理机代码数据3:为什么使用多线程使UI响应更快利用多处理器系统简化建模4:代码示例:Java中实现多线程的两种方式,包括如何定义多线程…