qt学习(三) qt布局
使用横向与竖向、网格三种布局嵌套使用后可以组合出很复杂的界面。
这里向大家推荐这篇博客
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布局的更多相关文章
- Qt学习笔记-Widget布局管理
Qt学习笔记4-Widget布局管理 以<C++ GUI Programming with Qt 4, Second Edition>为参考 实例:查找对话框 包含三个文件,f ...
- PyQt(Python+Qt)学习随笔:布局控件layout的layoutSizeConstraint属性不起作用的问题解决办法
在<PyQt(Python+Qt)学习随笔:布局控件layout的layoutSizeConstraint属性>中介绍layout的layoutSizeConstraint属性后,反复测试 ...
- Qt学习记录--Qt::CaseSensitive
Qt::CaseSensitivity 为枚举类型, 可取值Qt::CaseSensitive 和 Qt::CaseInsensitive, 表示匹配的灵敏度. 比较字符串的时候 Qt::CaseSe ...
- PyQt(Python+Qt)学习随笔:布局控件layoutStretch属性
在Qt Designer中布局控件有4个,分别是Vertical Layout(垂直布局).Horizontal Layout(水平布局).Grid Layout(网格布局).Form Layout( ...
- PyQt(Python+Qt)学习随笔:布局控件layout的layoutSizeConstraint属性
在Qt Designer中布局控件有4个,分别是Vertical Layout(垂直布局).Horizontal Layout(水平布局).Grid Layout(网格布局).Form Layout( ...
- PyQt(Python+Qt)学习随笔:布局控件layout的LeftMargin等contentsMargins属性
在Qt Designer中布局控件有4个,分别是Vertical Layout(垂直布局).Horizontal Layout(水平布局).Grid Layout(网格布局).Form Layout( ...
- PyQt(Python+Qt)学习随笔:布局控件layoutSpacing属性
在Qt Designer中布局控件有4个,分别是Vertical Layout(垂直布局).Horizontal Layout(水平布局).Grid Layout(网格布局).Form Layout( ...
- 【QT学习】QT GUI应用程序的框架,文件分析
有几个名字,项目名,类名,界面对象名. 1.项目文件 项目名.pro(MyHelloQt.pro) 主要包括项目用到的模块,项目包含哪些源码文件,头文件,窗体文件,生成应用程序的名称. 由QT自动生成 ...
- qt学习(一) qt安装
QT5现在安装已经方便了许多 相比QT4 可以一路点击到底 无需额外的太多的操作. http://download.qt.io/official_releases/ 下载 1 windows下可以选择 ...
随机推荐
- 利用Web Services开发分布式应用
一.引言 在前面文章中分别介绍了MSMQ和.NET Remoting技术,今天继续分享.NET 平台下另一种分布式技术——Web Services 二.Web Services 详细介绍 2.1 We ...
- HDU5033 Building(单调栈)
题意是说在水平轴上有很多建筑物(没有宽度),知道每个建筑物的位置与高度.有m个查询,每次查询位置x所能看到的天空的角度. 方法是将建筑与查询一起排序,从左往右计算一遍,如果是建筑物,则比较最后两个(当 ...
- 【转】 python 删除非空文件夹
转自:https://blog.csdn.net/xiaodongxiexie/article/details/77155864 一般删除文件时使用os库,然后利用os.remove(path)即可完 ...
- goaccess nginx日志分析工具简单使用
goaccess 是一个比较方便的支持实时的日志分析工具,比较方便,同时安装&&配置简单 安装 centos yum yum install -y goaccess 运行 我的ngin ...
- p/Invoke工具
开源的工具 下面这个链接来下载这个工具: http://download.microsoft.com/download/f/2/7/f279e71e-efb0-4155-873d-5554a06085 ...
- Trie树学习1
Trie树.也称为字典数,前缀树,每一个单词的每一个字母依照顺序相应一个节点.有重合的前缀就共享节点. 理想情况下(满的情况).假若全部的单词都是N长,则树共同拥有N层,每层都是26个子节点. 在程序 ...
- Mybatis 插件实现动态设置参数
原文地址:Mybatis 插件实现动态设置参数 博客地址:http://www.extlight.com 一.背景 笔者在搭建架构时,通常会利用泛型对 dao 层 和 service 层公共的代码(增 ...
- Java 正则表达式详细实例解析
案例1:判断字符串是否是abc package Regex; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * ...
- Jmeter的参数配置
Ramp-up Period(in seconds) [1]决定多长时间启动所有线程.如果使用10个线程,ramp-up period是100秒,那么JMeter用100秒使所有10个线程启动并运行. ...
- Bootstrap-Other:HTML编码规范
ylbtech-Bootstrap-Other:HTML编码规范 1.返回顶部 1. Bootstrap HTML编码规范 语法 用两个空格来代替制表符(tab) -- 这是唯一能保证在所有环境下获得 ...