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 ...
随机推荐
- Python安装升级步骤
1)安装Pyhton2.7wget http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tar.bz2tar xjvf Python-2.7.5.t ...
- HDU - 5307 :He is Flying (分治+FFT)(非正解)
JRY wants to drag racing along a long road. There are nn sections on the road, the ii-th section has ...
- 如何加快Json 序列化?有哪些方法?
1.使用阿里的fastjson 2.可以通过去除不必要属性加快序列化.如person对象,有id,name,address,我json需要用户姓名,此时序列化的时候就只序列化name,id和addre ...
- 19年博客flag
目录 为什么没有年终总结 为什么今天更新了 19年博客flag 个人博客链接:我在马路边 https://hhongwen.cn 更好的阅读体验点击查看原文:19年博客flag 原创博客,转载请注明出 ...
- BZOJ4604:The kth maximum number
浅谈离线分治算法:https://www.cnblogs.com/AKMer/p/10415556.html 题目传送门:https://lydsy.com/JudgeOnline/problem.p ...
- mysql的备份恢复等操作
备份数据库 shell> mysqldump -h host -u root -p dbname >dbname_backup.sql 恢复数据库 shell> mysqladmin ...
- Spring学习十一
一: 创建bean的方法: 1: 如果不采用构造注入:默认调用bean的无参构造函数,因此该类必须要提供无参构造函数,用无参构造函数用反射创建bean. : 如果采用构造 ...
- 将Windows下磁盘出现黑色为分配区域变成绿色区域
在windows下不知什么原因, 有一块磁盘空间F盘就变成了黑色为分配区域. 黑色区域无法用来安装双系统, 网上查阅资料后, 找到了如何将他重新变回绿色区域的2个方法(方法二是自己无意操作成功的). ...
- 2.《Spring学习笔记-MVC》系列文章,讲解返回json数据的文章共有3篇,分别为:
转自:https://www.cnblogs.com/ssslinppp/p/4528892.html 个人认为,使用@ResponseBody方式来实现json数据的返回比较方便,推荐使用. 摘要 ...
- C语言学习笔记--函数与指针
1. 函数类型 (1)C 语言中的函数有自己特定的类型,这个类型由返回值.参数类型和参数个数共同决定.如 int add(int i,int j)的类型为 int(int,int). (2)C 语言中 ...