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 ...
随机推荐
- Leetcode 970. Powerful Integers
Brute Force(暴力) class Solution(object): def powerfulIntegers(self, x, y, bound): """ ...
- inndb索引原理
###详解b+树如上图,是一颗b+树,关于b+树的定义可以参见B+树,这里只说一些重点,浅蓝色的块我们称之为一个磁盘块,可以看到每个磁盘块包含几个数据项(深蓝色所示)和指针(黄色所示),如磁盘块1包含 ...
- Busybox shell脚本修改密码
/****************************************************************************** * Busybox shell脚本修改密 ...
- 图m的着色问题(搜索)
图的m着色问题 [问题描述] 给定无向连通图G和m种不同的颜色.用这些颜色为图G的各顶点着色,每个顶点着一种颜色.如果有一种着色法使G中每条边的2个顶点着不同颜色,则称这个图是m可着色的 ...
- DIV设置浮动float以后下一个DIV要换行的方法
<div style=“float:left;”> 1111111 </div> <div style=“float:left;”>222222 </div& ...
- PhantomJS python 截屏
参考:https://www.cnblogs.com/LanTianYou/p/5578621.html # coding:utf8 from time import sleep from selen ...
- 如何修改MAC自带的PHP的版本?
1. 切换到root目录,新建“.profile”文件 cd ~ vim .profile 2.在.profile文件中添加PATH环境变量 比如这样的路径 export PATH=/Applicat ...
- 蓝桥杯 算法训练 ALGO-118 连续正整数的和
算法训练 连续正整数的和 时间限制:1.0s 内存限制:256.0MB 问题描述 78这个数可以表示为连续正整数的和,1+2+3,18+19+20+21,25+26+27. 输入一个正整数 n ...
- HDU5469(树的dfs)
Antonidas Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- Linux驱动中获取系统时间
最近在做VoIP方面的驱动,总共有16个FXS口和FXO口依次初始化,耗用的时间较多.准备将其改为多线程,首先需要确定哪个环节消耗的时间多,这就需要获取系统时间. #include <linux ...