使用横向与竖向、网格三种布局嵌套使用后可以组合出很复杂的界面。

这里向大家推荐这篇博客

http://www.cnblogs.com/Bonker/p/3454956.html

我这里使用布局做了一个对话框界面 作为练习

代码如下

qt5

QT creater创建一个Widgets application

不过没有使用该工程的UI

修改main.cpp

//#include "mainwindow.h"
#include <QApplication>
#include "QTestDialog.h" int main(int argc, char *argv[])
{
QApplication a(argc, argv);
TestDialog* tdialog = new TestDialog;
tdialog->show();
return a.exec();
}

添加 

QTestDialog.h
QTestDialog.cpp
#ifndef QTESTDIALOG_H
#define QTESTDIALOG_H #include <QDialog>
#include <QTextEdit>
#include <QPushButton>
#include <QLayout> class TestDialog:public QDialog
{
Q_OBJECT
public:
TestDialog(QWidget *parent = 0);
private:
QTextEdit* textEdit_1;
QTextEdit* textEdit_2;
QTextEdit* textEdit_3;
QPushButton* pushButton_1;
QPushButton* pushButton_2;
QPushButton* pushButton_3;
QPushButton* pushButton_4;
QPushButton* pushButton_5;
};
#endif // QTESTDIALOG_H

  

#include <QApplication>
#include "qtestdialog.h" TestDialog::TestDialog(QWidget *parent)
: QDialog(parent)
{
pushButton_1 = new QPushButton(tr("字体"));
pushButton_2 = new QPushButton(tr("大小"));
pushButton_3 = new QPushButton(tr("消息记录")); QHBoxLayout* toolLayout = new QHBoxLayout;
toolLayout->addWidget(pushButton_1);
toolLayout->addWidget(pushButton_2);
toolLayout->addStretch();
toolLayout->addWidget(pushButton_3); pushButton_4 = new QPushButton(tr("关闭"));
pushButton_5 = new QPushButton(tr("发送"));
QHBoxLayout* buttomLayout = new QHBoxLayout;
buttomLayout->addStretch();
buttomLayout->addWidget(pushButton_4);
buttomLayout->addWidget(pushButton_5); textEdit_1 = new QTextEdit;
textEdit_2 = new QTextEdit;
textEdit_2->setMaximumHeight(90);
QVBoxLayout* leftlayout = new QVBoxLayout;
leftlayout->addWidget(textEdit_1);
leftlayout->addLayout(toolLayout);
leftlayout->addWidget(textEdit_2);
leftlayout->addLayout(buttomLayout); textEdit_3 = new QTextEdit;
textEdit_3->setMaximumWidth(100);
QVBoxLayout* rightlayout = new QVBoxLayout;
rightlayout->addWidget(textEdit_3); QHBoxLayout* toplayout = new QHBoxLayout;
toplayout->addLayout(leftlayout);
toplayout->addLayout(rightlayout); QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addLayout(toplayout);
setLayout(mainLayout); }

  

 最后效果图

qt学习(三) qt布局的更多相关文章

  1. Qt学习笔记-Widget布局管理

    Qt学习笔记4-Widget布局管理       以<C++ GUI Programming with Qt 4, Second Edition>为参考 实例:查找对话框 包含三个文件,f ...

  2. PyQt(Python+Qt)学习随笔:布局控件layout的layoutSizeConstraint属性不起作用的问题解决办法

    在<PyQt(Python+Qt)学习随笔:布局控件layout的layoutSizeConstraint属性>中介绍layout的layoutSizeConstraint属性后,反复测试 ...

  3. Qt学习记录--Qt::CaseSensitive

    Qt::CaseSensitivity 为枚举类型, 可取值Qt::CaseSensitive 和 Qt::CaseInsensitive, 表示匹配的灵敏度. 比较字符串的时候 Qt::CaseSe ...

  4. PyQt(Python+Qt)学习随笔:布局控件layoutStretch属性

    在Qt Designer中布局控件有4个,分别是Vertical Layout(垂直布局).Horizontal Layout(水平布局).Grid Layout(网格布局).Form Layout( ...

  5. PyQt(Python+Qt)学习随笔:布局控件layout的layoutSizeConstraint属性

    在Qt Designer中布局控件有4个,分别是Vertical Layout(垂直布局).Horizontal Layout(水平布局).Grid Layout(网格布局).Form Layout( ...

  6. PyQt(Python+Qt)学习随笔:布局控件layout的LeftMargin等contentsMargins属性

    在Qt Designer中布局控件有4个,分别是Vertical Layout(垂直布局).Horizontal Layout(水平布局).Grid Layout(网格布局).Form Layout( ...

  7. PyQt(Python+Qt)学习随笔:布局控件layoutSpacing属性

    在Qt Designer中布局控件有4个,分别是Vertical Layout(垂直布局).Horizontal Layout(水平布局).Grid Layout(网格布局).Form Layout( ...

  8. 【QT学习】QT GUI应用程序的框架,文件分析

    有几个名字,项目名,类名,界面对象名. 1.项目文件 项目名.pro(MyHelloQt.pro) 主要包括项目用到的模块,项目包含哪些源码文件,头文件,窗体文件,生成应用程序的名称. 由QT自动生成 ...

  9. qt学习(一) qt安装

    QT5现在安装已经方便了许多 相比QT4 可以一路点击到底 无需额外的太多的操作. http://download.qt.io/official_releases/ 下载 1 windows下可以选择 ...

随机推荐

  1. [BZOJ3470]Freda’s Walk

    bzoj description 雨后的Poetic Island空气格外清新,于是Freda和Rainbow出来散步. Poetic Island的交通可以看作一张\(n\)个点.\(m\)边的有向 ...

  2. kudu yum 安装

    yum 源 http://archive.cloudera.com/kudu/redhat/7/x86_64/kudu/cloudera-kudu.repo [cloudera-kudu] # Pac ...

  3. wamp安装后无法正常启动(80端口被占用)

    关于wamp启动是80端口被占用的问题详解(win7系统下WAMP 80端口被Microsoft-HTTPAPI/2.0占用的解决办法) VS2010在更新了SP1后,会在开机时自动启动一个服务,占用 ...

  4. VC6 快捷键

    F1: 帮助 Alt+F8   : 自动缩进Ctrl+O   :OpenCtrl+P   :PrintCtrl+N   :NewCtrl+Shift+F2 :清除所有书签F2    :上一个书签Shi ...

  5. Non-standard evaluation, how tidy eval builds on base R

    As with many aspects of the tidyverse, its non-standard evaluation (NSE) implementation is not somet ...

  6. UI“三重天”之selenium--封装(二)

    基础示例代码: /** * @author Richered **/ package com.sample; import org.openqa.selenium.By; import org.ope ...

  7. Oracle 字符集的查看和修改 --转载

    原文地址:Oracle 字符集的查看和修改 作者:piaoliuxiong 一.什么是Oracle字符集 Oracle字符集是一个字节数据的解释的符号集合,有大小之分,有相互的包容关系.ORACLE  ...

  8. 笔记本制作centos qcow2格式文件

    笔记本win7先通过vbox安装好centos6.5 然后打开cmd命令行在c:\Program Files\Oracle\VirtualBox下执行 vboxmanage clonehd --for ...

  9. 使用sqoop从Oracle或mysql抽取数据到HDFS遇到的报错及解决

    一.参考文档: 1.https://www.rittmanmead.com/blog/2014/03/using-sqoop-for-loading-oracle-data-into-hadoop-o ...

  10. python 构造mysql爆破器

    前言: 今天已经期末考完,睡了个觉起床写了个 mysql爆破器. 思路: 1.爆破用户->用户存在的话不会报错反之报错 2.爆破密码->密码正确不会报错反之报错 3.用户名和密码一起爆破- ...