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 ...
随机推荐
- CodeForces - 896D :Nephren Runs a Cinema(卡特兰数&组合数学---比较综合的一道题)
Lakhesh loves to make movies, so Nephren helps her run a cinema. We may call it No. 68 Cinema. Howev ...
- 如何卸载Python通过setup.py安装的模块
0,pip uninstall xxxx 1.找到egg sudo easy_install -m BitVector .... Using /usr/local/lib/python2./ ...
- python发短信功能
http://www.cnblogs.com/martianShu/p/5847289.html
- 学习动态性能表(11)v$latch$v$latch_children
学习动态性能表 第十一篇-(1)-V$LATCH 2007.6.7 Oracle Rdbms应用了各种不同类型的锁定机制,latch即是其中的一种.Latch是用于保护SGA区中共享数据结构的一种串 ...
- vue.js初学(二)
1:构造器 var app = new Vue ( { //选项 }) 注意点: (1) 之后会经常用vm代表Vue实例 (2)实例化之后 需要传入一个选项对象,它可以包括数据.模板.挂载元素.方法. ...
- bzoj 4403 序列统计——转化成组合数的思路
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4403 先说说自己的想法吧. 设f[ i ][ j ]表示当前在倒数第 i 个位置,当前和后面 ...
- 聊聊基于Lucene的搜索引擎核心技术实践
最近公司用到了ES搜索引擎,由于ES是基于Lucene的企业搜索引擎,无意间在“聊聊架构”微信公众号里发现了这篇文章,分享给大家. 请点击链接:聊聊基于Lucene的搜索引擎核心技术实践
- iperf 网络测速
1.介绍 1) # ipref -g //这个最直观 2)Iperf 是一个网络性能测试工具.Iperf可以测试最大TCP和UDP带宽性能.Iperf具有多种参数和UDP特性,可以根据需要调整. ...
- mybatis association表关联与rowbounds共同使用时的异常及其解决方案
按照mybatis手册中所说的,association有两种实现方式,嵌套查询和嵌套结果映射.如手册中所述,select方式会带来N+1次查询的问题,考虑到效率问题的话建议使用嵌套结果映射.但是在结合 ...
- [cinder] volume type 使用简记
cinder type-create sharecinder type-key share set volume_backend_name=GLUSTERFScinder type-create lo ...