使用过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的更多相关文章

  1. 读Qt Demo——Basic Layouts Example

    此例程主要展示用代码方式创建控件并用Layout管理类对其进行布局: 例程来自Qt5.2,如过是默认安装,代码位于:C:\Qt\Qt5.2.0\5.2.0\mingw48_32\examples\wi ...

  2. Useful Qt Examples

    Canvas API Basic Layouts Camera Example Video Widget Example Image Viewer Example Part 6 - Loading a ...

  3. Qt Examples Qt实例汇总

    ActiveQt Examples Using ActiveX from Qt applications. Animation Framework Examples Doing animations ...

  4. SiteMesh详解

    Sitemesh是一种页面装饰技术:它通过过滤器(filter)来拦截页面访问,据被访问页面的URL找到合适的装饰模板等等,感兴趣的朋友可以了解下哦 一,基本概念 1,Sitemesh是一种页面装饰技 ...

  5. [转]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 ...

  6. USACO 6.2 Packing Rectangles

    Packing RectanglesIOI 95 The six basic layouts of four rectangles Four rectangles are given. Find th ...

  7. sitemesh 学习之 meta 引入

    在上篇笔记学习了sitemesh的基本用法,这里还有另一种用法 在sitemesh.jar有一个默认的sitemesh-default文件 ,这个文件是可以指定的 可以指定的文件名的sitemesh. ...

  8. Tutorial: Publishing additional services for printing

    Complexity:IntermediateData Requirement:Use your own data There may be occasions when you need to pu ...

  9. BookStore示例项目---菜单栏UI分析

    部署 参照 ABP示例项目BookStore搭建部署 项目解构 1).动态脚本代理 启动项目时,默认会调用两个接口 /Abp/ApplicationConfigurationScript /Abp/S ...

随机推荐

  1. UVA - 11019 Matrix Matcher (二维字符串哈希)

    给你一个n*m的矩阵,和一个x*y的模式矩阵,求模式矩阵在原矩阵中的出现次数. 看上去是kmp在二维情况下的版本,但单纯的kmp已经无法做到了,所以考虑字符串哈希. 类比一维情况下的哈希算法,利用容斥 ...

  2. LeetCode 314. Binary Tree Vertical Order Traversal

    原题链接在这里:https://leetcode.com/problems/binary-tree-vertical-order-traversal/ 题目: Given a binary tree, ...

  3. PCM音量控制

    http://blog.jianchihu.net/pcm-volume-control.html 一.声音的相关概念 声音是介质振动在听觉系统中产生的反应.声音总可以被分解为不同频率不同强度正弦波的 ...

  4. 洛谷【P1140】相似基因

    浅谈\(DP\):https://www.cnblogs.com/AKMer/p/10437525.html 题目传送门:https://www.luogu.org/problemnew/show/P ...

  5. java中final用法

    1.修饰基础数据成员 这是final的主要用途,其含义相当于C/C++的const,即该成员被修饰成常量,不可修改. 2.修饰类或者对象的引用的final 在java中我们无法让对象被修饰为final ...

  6. MyBatis定制SQL集中特殊的处理方式

    举例说明: 1.查询 姓为林的数据  LIKE 3种 Select * from sys_user where user_name like '林%' 关于结果集合多个参数传递数据 特殊字符的处理

  7. hihoCoder#1175拓扑排序应用

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho所在学校的校园网被黑客入侵并投放了病毒.这事在校内BBS上立刻引起了大家的讨论,当然小Hi和小Ho也参与到了 ...

  8. ramfs, rootfs and initramfs

    ramfs, rootfs and initramfs October 17, 2005 Rob Landley <rob@landley.net> =================== ...

  9. Python中获得当前目录和上级目录

    [转]原文地址:http://blog.csdn.net/liuweiyuxiang/article/details/71154346 获取当前文件的路径: from os import path d ...

  10. python selenium 滚动条处理、页面拖动

    selenium中没有直接控制滚动条的方法,可以使用方法:execute_script(),可以直接执行js的脚本. 一.竖向滚动条控制,三种方法总有一款适合你. 1.滚动条拉到最底: js=&quo ...