1.Basic Layouts
使用过mfc编程,就知道控件需要自己拖放。当一个界面有很多小控件时,摆放这些控件特别麻烦。
但是qt编程中有布局(Layout),让系统来摆放控件。使整个控件有一致的外观和感觉,特别方便。
1.水平方向的布局 QHBoxLayout

思考:
简单的把控件添加到布局里面就ok了。
horizontalGroupbox = new QGroupBox("Horizontal Layout");
hlayout = new QHBoxLayout;
QPushButton *button1 = new QPushButton("Button1");
QPushButton *button2 = new QPushButton("Button2");
QPushButton *button3 = new QPushButton("Button3");
QPushButton *button4 = new QPushButton("Button4");
hlayout->addWidget(button1);
hlayout->addWidget(button2);
hlayout->addWidget(button3);
hlayout->addWidget(button4);
horizontalGroupbox->setLayout(hlayout);
2.栅格布局。QGridLayout

思考:
1.grid layout是按行列来进行布局的。
2.这个布局有4行,3列。
3.第一行只有一个QTextEdit,但是它横跨4行。
4.第二列比第一列长,第三列比第二列长。原因是调用了 setRowStretch()函数。
gridGroupbox = new QGroupBox("Grid Layout");
gridLayout = new QGridLayout;
label1 = new QLabel("Line1");
label2 = new QLabel("Line2");
label3 = new QLabel("Line3");
lineEdit1 = new QLineEdit;
lineEdit2 = new QLineEdit;
lineEdit3 = new QLineEdit;
textEdit = new QTextEdit;
textEdit->setPlainText(tr("This widget takes up two thirds of grid layout"));
gridLayout->addWidget(textEdit, , , , );
gridLayout->addWidget(label1, , );
gridLayout->addWidget(label2, , );
gridLayout->addWidget(label3, , );
gridLayout->addWidget(lineEdit1, , );
gridLayout->addWidget(lineEdit2, , );
gridLayout->addWidget(lineEdit3, , );
gridLayout->setRowStretch(, );
gridLayout->setRowStretch(, );
gridGroupbox->setLayout(gridLayout);
3.表单布局 QFormLayout

思考:
1.表单布局是一种只有2列的布局。
2.表单布局可以用gridlayout实现,但是表单布局简单一些。
3.addRow方法,直接添加label 和 widget。
formGroupBox = new QGroupBox("Form Layout");
formLayout = new QFormLayout;
formLineEdit = new QLineEdit;
comboBox = new QComboBox;
spinBOx = new QSpinBox;
formLayout->addRow(tr("Line1"), formLineEdit);
formLayout->addRow(tr("Line2,Long Text:"), comboBox);
formLayout->addRow(tr("Line3"), spinBOx);
formGroupBox->setLayout(formLayout);
4.竖直方向布局。
把刚才布局都添加到竖直布局,就是我们整个程序
mainLayout = new QVBoxLayout;
mainLayout->addWidget(horizontalGroupbox);
mainLayout->addWidget(gridGroupbox);
mainLayout->addWidget(formGroupBox);
mainLayout->addWidget(bigTextEdit);
mainLayout->addWidget(buttonBox, , Qt::AlignRight);
1.Basic Layouts的更多相关文章
- 读Qt Demo——Basic Layouts Example
此例程主要展示用代码方式创建控件并用Layout管理类对其进行布局: 例程来自Qt5.2,如过是默认安装,代码位于:C:\Qt\Qt5.2.0\5.2.0\mingw48_32\examples\wi ...
- Useful Qt Examples
Canvas API Basic Layouts Camera Example Video Widget Example Image Viewer Example Part 6 - Loading a ...
- Qt Examples Qt实例汇总
ActiveQt Examples Using ActiveX from Qt applications. Animation Framework Examples Doing animations ...
- SiteMesh详解
Sitemesh是一种页面装饰技术:它通过过滤器(filter)来拦截页面访问,据被访问页面的URL找到合适的装饰模板等等,感兴趣的朋友可以了解下哦 一,基本概念 1,Sitemesh是一种页面装饰技 ...
- [转]How To Send Transactional Email In A NodeJS App Using The Mailgun API
https://www.npmjs.com/package/mailgun-js 本文转自:https://www.mailgun.com/blog/how-to-send-transactional ...
- USACO 6.2 Packing Rectangles
Packing RectanglesIOI 95 The six basic layouts of four rectangles Four rectangles are given. Find th ...
- sitemesh 学习之 meta 引入
在上篇笔记学习了sitemesh的基本用法,这里还有另一种用法 在sitemesh.jar有一个默认的sitemesh-default文件 ,这个文件是可以指定的 可以指定的文件名的sitemesh. ...
- Tutorial: Publishing additional services for printing
Complexity:IntermediateData Requirement:Use your own data There may be occasions when you need to pu ...
- BookStore示例项目---菜单栏UI分析
部署 参照 ABP示例项目BookStore搭建部署 项目解构 1).动态脚本代理 启动项目时,默认会调用两个接口 /Abp/ApplicationConfigurationScript /Abp/S ...
随机推荐
- 程序员如何编写好开发技术文档 如何编写优质的API文档工作
编写技术文档,是令众多开发者望而生畏的任务之一.它本身是一件费时费力才能做好的工作.可是大多数时候,人们却总是想抄抄捷径,这样做的结果往往非常令人遗憾的,因为优质的技术文档是决定你的项目是否引人关注的 ...
- Buffer 和Cache 的区别
Buffer 和Cache 的区别buffer 与cache 操作的对象就不一样.buffer
- [基本操作] kd 树
概念就不说了吧,网上教程满天飞 学了半天才知道,kd 树实质上只干了两件事情: 1.快速定位一个点 / 矩形 2.有理有据地优化暴力 第一点大概是可以来做二维平面上给点/矩形打标记的问题 第二点大概是 ...
- [ Laravel 5.5 文档 ] 处理用户请求 —— HTTP 请求的过滤器:中间件
[ Laravel 5.5 文档 ] 处理用户请求 —— HTTP 请求的过滤器:中间件 http://laravelacademy.org/post/7812.html 简介 中间件为过滤进入应用的 ...
- git之cherry-pick
当想把当前分支提交的代码,也在其他分支提交,那可以用cherry-pick命令. 1 假设在master分支commit的id为:abc12345; 2 切换到其他分支,如develop分支; 3 在 ...
- 用PHP编写登陆界面
网页的编写用PHP最方便.用php做了最简单的用户登录.创建的程序. 一. MySQL的设计 MySQL设计了两个表:members和sex.两张表的创建语句分别是: create table mem ...
- 关于java.lang.ClassNotFoundException
关于java.lang.ClassNotFoundException,在自己的程序中,也出现过好几次了,每次找到原因之后,又会发觉原来是以前处理过的. java.lang.ClassNotFoundE ...
- [转】LTE整体架构和协议架构概述
1.1 LTE整体架构 LTE(Long Term Evolution,长期演进)是由3GPP(The 3rd Generation Partnership Project,第三代合作伙伴计划)组织制 ...
- java restful response 万能类
import java.util.HashMap; import java.util.Map; public class ResponseData { private final String mes ...
- 侯捷STL学习(六)--深入list && Iterator traits
第十三,四节 深度探索list(上,下) list Gnu2.9源代码实现 注意node代码和图示的位置 实现前闭后开,增加一个空白节点 用的分配器alloc Iterator智能指针,需要知道结点n ...