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下可以选择 ...
随机推荐
- WindowsXamlHost:在 WPF 中使用 UWP 的控件(Windows Community Toolkit)
Windows Community Toolkit 再次更新到 5.0.以前可以在 WPF 中使用有限的 UWP 控件,而现在有了 WindowsXamlHost,则可以使用更多 UWP 原生控件了. ...
- 前端安全系列:如何防止CSRF攻击?
背景 随着互联网的高速发展,信息安全问题已经成为企业最为关注的焦点之一,而前端又是引发企业安全问题的高危据点.在移动互联网时代,前端人员除了传统的 XSS.CSRF 等安全问题之外,又时常遭遇网络劫持 ...
- emacs之配置8,gdb调试设置
emacsConfig/gdb-setting.el (global-set-key [(f5)] 'gud-go) (global-set-key [(f7)] 'gud-step) (global ...
- 华为5573+联通4G上网SIM+ROS hap ac-RB962UiGS-5HacT2HnT 上网
华为5573+联通4G上网SIM+ROS hap ac-RB962UiGS-5HacT2HnT 上网 原理其实是这样的,ROS的USB口连接华为5573: 华为5573看成是一个路由器,他的外网网卡走 ...
- ROS创建Web代理(Web proxy)给QQ使用HTTP代理
使用Web代理可以提高网页的访问速度,因为访问的数据会存储在内存或是硬盘中,就会直接从代理服务器中读取.同时,为了提高网络访问的安全性,可以给Web代理服务器设置相应的权限,使它的安全性得到提高. 下 ...
- mysql-5.6.20主从同步错误之Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND
mysql-5.6.20主从同步错误之Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND 方法一: 1.Error_code: 1032; ha ...
- linux nginx安装以及配置
一.Nginx简介 Nginx (“engine x”) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器.Nginx是由Igor Sysoev为俄罗斯访问量第二的R ...
- 36. Valid Sudoku + 37. Sudoku Solver
▶ 有关数独的两个问题. ▶ 36. 检测当前盘面是否有矛盾(同一行.同一列或 3 × 3 的小框内数字重复),而不关心该盘面是否有解. ● 初版代码,24 ms,没有将格子检测函数独立出去,行检测. ...
- pandas的数据结构
要使用pandas,需要熟悉它的两个主要的数据结构,Series和DataFrame. Series series是一种类似于以为数组的对象,它由一组数据(各种numpy的数据类型)以及一组与之相关的 ...
- 如何量化考核技术人的 KPI?
如何量化考核技术人的 KPI? 原创: 张建飞 阿里技术今天 阿里妹导读:对技术人来说,技术是成长的"核心".然而,在实际工作协作中,技术的重要性常常被业务所掩盖,造成先业务后技术 ...