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下可以选择 ...
随机推荐
- SQL Server2008 R2开启远程连接总结
============================== SQL Server2008 R2开启远程连接(最全总结) ============================== 安装过程:适用W ...
- JFrog Artifactory CE c&&c++ 包管理工具
JFrog Artifactory CE 支持conan 以及普通二进制c&&c++包管理 使用docker 进行环境的搭建测试 安装 docker run -d -p 8081:80 ...
- Mybatis新增mysql时中文乱码
Mybatis新增mysql时中文乱码 1.设置数据库连接的编码(jdbc.properties) jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:my ...
- 归并排序算法-python实现
#-*- coding: UTF-8 -*- import numpy as np def Merge(a, f, m, l): i = f j = m + 1 tmp = [] while i &l ...
- CentOS查看显卡及GPU相关信息
lspci | grep -i vga 这样就可以显示机器上的显卡信息,比如 [root@localhost conf]# lspci | grep -i vga01:00.0 VGA compat ...
- cowboy添加验证码
参考的http://beebole.com/blog/erlang/how-to-implement-captcha-in-erlang-web-application/,移到cowboy,修改了下: ...
- 【详解】Linux的文件描述符fd与文件指针FILE*互相转换
使用系统调用的时候用文件描述符(file descriptor,简称fd)的时候比较多,但是操作比较原始.C库函数在I/O上提供了一些方便的包装(比如格式化I/O.重定向),但是对细节的控制不够. 如 ...
- nginx学习1
访问abc.xxx.com就跳转到www.xxx.com/abc.html server { listen 80; server_name abc.xxx.com; rewrite ^.*$ ww ...
- IDA python使用笔记
pattern='20 E5 40 00' addr=MinEA() for x in range(0,5): addr=idc.FindBinary(addr,SEARCH_DOWN,pat ...
- Traits
'folly/Traits.h' Implements traits complementary to those provided in <type_traits> Implements ...