当前位置:网站首页>Qt学习24 布局管理器(三)
Qt学习24 布局管理器(三)
2022-07-03 13:23:00 【一个小黑酱】
Qt学习24 布局管理器(三)
思考
如何设计下面的图形用户界面?

解决方案
- 绝对定位 组建的坐标和大小
- 嵌套 QBoxLayout
- 创建 3*2 的 QGridLayout

上述三种方式都或多或少存在问题, 绝对定位 需要计算坐标,嵌套 QBoxyLayout 需要使用4个布局管理器,而 3*2 的 QGridLayout 在窗口大小变化时,会产生比例系数固定的问题。
QFormLayout布局管理器
以 表单(Form) 的方式管理界面组件
表单布局 中的标签和组件是 相互对应 的关系
QFormLayout 的用法概要
- void addRow(QWidget *label, QWidget *field)
- void addRow(QWidget *label, QLayout *field)
- void addRow(const QString& labelText, QWidget *field)
- void addRow(const QString& labelText, QLayout *field)
表单布局 支持嵌套,其他布局管理器可以作为子布局被其管理
编程实验
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
};
#endif // WIDGET_H
#include "Widget.h"
#include <QLineEdit>
#include <QFormLayout>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
QLineEdit *nameEdit = new QLineEdit();
QLineEdit *mailEdit = new QLineEdit();
QLineEdit *addrEdit = new QLineEdit();
QFormLayout *layout = new QFormLayout();
layout->addRow("Name:", nameEdit);
layout->addRow("Email:", mailEdit);
layout->addRow("Address:", addrEdit);
// layout->setRowWrapPolicy(QFormLayout::WrapAllRows);
layout->setRowWrapPolicy(QFormLayout::WrapLongRows); // 自适应标签和编辑框
layout->setSpacing(10);
setLayout(layout);
setWindowTitle("FTP");
}
Widget::~Widget()
{
}
#include "Widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
QFormLayout 的样式函数
- void setRowWrapPolicy(RowWrapPolicy policy)
- void setLabelAlignment(Qt::Alignment alignment)
布局管理器的嵌套

小结
- QFormLayout 以 表单 的方式管理界面组件
- QFormLayout 的 样式 设置 简洁 明了
- QFormLayout 支持布局管理器的相互嵌套
- QFormLayout 是嵌入式产品中 最常用的布局方式
边栏推荐
- MySQL 数据增删改查综合案例
- Go language web development series 26: Gin framework: demonstrates the execution sequence of code when there are multiple middleware
- 记录关于银行回调post请求405 问题
- Mastering the cypress command line options is the basis for truly mastering cypress
- Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
- Golang — 命令行工具cobra
- PHP maze game
- Libuv库 - 设计概述(中文版)
- 常见的几种最优化方法Matlab原理和深度分析
- [quantitative trading] permanent portfolio, turtle trading rules reading, back testing and discussion
猜你喜欢

Go language web development series 30: gin: grouping by version for routing

The latest BSC can pay dividends. Any B usdt Shib eth dividend destruction marketing can

Kivy教程之 如何自动载入kv文件

如何使用lxml判断网站公告是否更新

TensorBoard可视化处理案例简析

使用vscode查看Hex或UTF-8编码

Another industry has been broken by Chinese chips. No wonder the leading analog chip companies in the United States have cut prices and sold off
![[技術發展-24]:現有物聯網通信技術特點](/img/f3/a219fe8e7438b8974d2226b4c3d4a4.png)
[技術發展-24]:現有物聯網通信技術特點

Go language unit test 5: go language uses go sqlmock and Gorm to do database query mock

Universal dividend source code, supports the dividend of any B on the BSC
随机推荐
CVPR 2022 | 美团技术团队精选6篇优秀论文解读
MySQL 数据处理值增删改
Go language unit test 3: go language uses gocovey library to do unit test
Spark practice 1: build spark operation environment in single node local mode
The latest BSC can pay dividends. Any B usdt Shib eth dividend destruction marketing can
Go 1.16.4: purpose of go mod tidy
Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:
JS convert pseudo array to array
Go language unit test 4: go language uses gomonkey to test functions or methods
实现CNN图像的识别和训练通过tensorflow框架对cifar10数据集等方法的处理
项目协作的进度如何推进| 社区征文
Golang - command line tool Cobra
[how to earn a million passive income]
Red hat satellite 6: better management of servers and clouds
Comprehensive evaluation of double chain notes remnote: fast input, PDF reading, interval repetition / memory
Ocean CMS vulnerability - search php
GoLand 2021.1: rename the go project
常见的几种最优化方法Matlab原理和深度分析
Go language unit test 5: go language uses go sqlmock and Gorm to do database query mock
Mobile phones and computers can be used, whole people, spoof code connections, "won't you Baidu for a while" teach you to use Baidu