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下可以选择 ...
随机推荐
- .NET 命令行参数包含应用程序路径吗?
如果你关注过命令行参数,也许发现有时你会在命令行参数的第一个参数中中看到应用程序的路径,有时又不会.那么什么情况下有路径呢? 其实是否有路径只是取决于获取命令行参数的时候用的是什么方法.而这是 Win ...
- 使用caddy 进行nodejs web应用近实时编译更新
caddy 相比nginx 是一个不错的轻量代理服务器,支持的功能也是比较多的, 同时插件也挺多 demo 测试的是通过git 插件进行一个使用spec-md 编写的文档近实时编译以及预览 项目使用d ...
- apache伪静态设置
在网站根目录下新建一个.htaccess文件即可,编辑如下 RewriteEngine On #游戏列表详细介绍 RewriteRule ^g-([0-9]+).html$ game.php?acti ...
- 【转】shell 编程:冒号 后面跟 等号,加号,减号,问号的意义
原文网址:http://blog.csdn.net/trochiluses/article/details/9048539 缺省值(:-) 如果变量后面跟着冒号和减号,则变量后面跟着是这个变量的缺 ...
- 为eclipse安装python、shell开发环境和SVN插件
http://www.crazyant.net/1185.html 为eclipse安装python.shell开发环境和SVN插件 2013/08/27 by Crazyant 暂无评论 eclip ...
- 7z 7zip 日期、时间,文件名
from: http://hi.baidu.com/guicomeon/item/c0957c373972fbc52f8ec26e 先说明一点,要注意区分当前所使用的系统,中文系统和英文系统是有区别的 ...
- Tomcat服务器端口的配置
一.Tomcat服务器端口的配置 Tomcat的所有配置都放在conf文件夹之中,里面的server.xml文件是配置的核心文件. 如果想修改Tomcat服务器的启动端口,则可以在server.xml ...
- erlang otp中的socket参数设置
抄自http://www.zackzod.me/2012/10/24/socket-options-in-erlang-otp.html Erlang的inet模块里提供了对Socket进行一系列参数 ...
- char、varchar、varchar2区别
char varchar varchar2 的区别 区别:1.CHAR的长度是固定的,而VARCHAR2的长度是可以变化的, 比如,存储字符串“abc",对于CHAR (20),表示你存储的 ...
- MySQL单机单实例安装脚本
说明:使用mysql generic tar.gz包快速安装mysql 三个文件installation_of_single_mysql.sh.template_install-my.cnf.mysq ...