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 ...
随机推荐
- 剑指offer--17.第一个只出现一次的字符
map默认对key进行排序,unordered_map不对键或值进行排序,但是也不是默认插入的顺序 -------------------------------------------------- ...
- BEC translation exercise 7
在挑选时我们完全出自疏忽而漏过了这篇短文.In making the selection we passed this short piece by quite inadvertently. we l ...
- python 字符串大小写相关函数
改写:(都不会改变原字符串) s = 'hEllo wOrld' s Out[3]: 'hEllo wOrld' s.upper()#全部大写 Out[4]: 'HELLO WORLD' s Out[ ...
- OpenCV 2.4.9 +VS2013 开发环境配置
OpenCV 的全称是:Open Source Computer Vision Library.OpenCV是一个基于(开源)发行的跨平台计算机视觉库,可以运行在Linux.Windows和Mac O ...
- Jtable实现
package database; import java.util.Vector; import javax.swing.table.AbstractTableModel; public class ...
- Yii的常用URL和渲染方法
当前页面url Yii::app()->request->url;跳转前一个页面url $this->redirect(Yii::app()->request->url ...
- Python函数-callable()
callable(object) 作用: 检查对象object是否可调用.如果返回True,object仍然可能调用失败:但如果返回False,调用对象ojbect绝对不会成功. 注意: 类是可调用的 ...
- Python List reverse()方法
reverse() 函数用于反向列表中元素,参数 NA,该方法没有返回值,但是会对列表的元素进行反向排序,原来的列表被改变,生成新的列表. 例子:list1 = ['Google', 'Runoob' ...
- (转载)Windows: "net use" command introduction
1)建立空连接: net use ""IP"ipc$ "" /user:"" (一定要注意:这一行命令中包含了3个空格) 2)建立 ...
- commandLink/commandButton/ajax backing bean action/listener method not invoked (转)
Whenever an UICommand component fails to invoke the associated action method or an UIInputelement fa ...