当前位置:网站首页>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 是嵌入式产品中 最常用的布局方式
边栏推荐
- Libuv Library - Design Overview (Chinese version)
- Internet of things completion -- (stm32f407 connects to cloud platform detection data)
- Start signing up CCF C ³- [email protected] chianxin: Perspective of Russian Ukrainian cyber war - Security confrontation and sanctions g
- JSON serialization case summary
- 【电脑插入U盘或者内存卡显示无法格式化FAT32如何解决】
- Windos creates Cordova prompt because running scripts is prohibited on this system
- Resolved (error in viewing data information in machine learning) attributeerror: target_ names
- 如何使用lxml判断网站公告是否更新
- CVPR 2022 | interpretation of 6 excellent papers selected by meituan technical team
- [how to solve FAT32 when the computer is inserted into the U disk or the memory card display cannot be formatted]
猜你喜欢
![[développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes](/img/f3/a219fe8e7438b8974d2226b4c3d4a4.png)
[développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes

Go language web development series 26: Gin framework: demonstrates the execution sequence of code when there are multiple middleware

logback日志的整理

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

【电脑插入U盘或者内存卡显示无法格式化FAT32如何解决】

AI 考高数得分 81,网友:AI 模型也免不了“内卷”!

MySQL 数据增删改查综合案例

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

There is nothing new under the sun. Can the meta universe go higher?

Kivy tutorial how to automatically load kV files
随机推荐
Error handling when adding files to SVN:.... \conf\svnserve conf:12: Option expected
RichView TRVStyle ListStyle 列表样式(项目符号编号)
Unity Render Streaming通过Js与Unity自定义通讯
Go language web development series 26: Gin framework: demonstrates the execution sequence of code when there are multiple middleware
MapReduce implements matrix multiplication - implementation code
IBEM mathematical formula detection data set
The principle of human voice transformer
双链笔记 RemNote 综合评测:快速输入、PDF 阅读、间隔重复/记忆
Internet of things completion -- (stm32f407 connects to cloud platform detection data)
MapReduce实现矩阵乘法–实现代码
SQL Injection (GET/Search)
树的深入和广度优先遍历(不考虑二叉树)
Unable to stop it, domestic chips have made another breakthrough, and some links have reached 4nm
全面发展数字经济主航道 和数集团积极推动UTONMOS数藏市场
【被动收入如何挣个一百万】
GoLand 2021.2 configure go (go1.17.6)
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
Comprehensive evaluation of double chain notes remnote: fast input, PDF reading, interval repetition / memory
The shortage of graphics cards finally came to an end: 3070ti for more than 4000 yuan, 2000 yuan cheaper than the original price, and 3090ti
刚毕业的欧洲大学生,就能拿到美国互联网大厂 Offer?