当前位置:网站首页>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 是嵌入式产品中 最常用的布局方式
边栏推荐
- Kivy教程之 如何通过字符串方式载入kv文件设计界面(教程含源码)
- Complete DNN deep neural network CNN training with tensorflow to complete image recognition cases
- Flutter dynamic | fair 2.5.0 new version features
- Mastering the cypress command line options is the basis for truly mastering cypress
- Setting up remote links to MySQL on Linux
- 如何使用lxml判断网站公告是否更新
- Leetcode-1175. Prime Arrangements
- Go: send the get request and parse the return JSON (go1.16.4)
- Go language unit test 3: go language uses gocovey library to do unit test
- There is nothing new under the sun. Can the meta universe go higher?
猜你喜欢

Halcon combined with C # to detect surface defects -- Halcon routine autobahn

SQL Injection (GET/Select)

NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon

Resource Cost Optimization Practice of R & D team
![[how to solve FAT32 when the computer is inserted into the U disk or the memory card display cannot be formatted]](/img/95/09552d33d2a834af4d304129714775.png)
[how to solve FAT32 when the computer is inserted into the U disk or the memory card display cannot be formatted]

Several common optimization methods matlab principle and depth analysis

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

8 Queen question

PhpMyAdmin stage file contains analysis traceability

Comprehensively develop the main channel of digital economy and digital group, and actively promote the utonmos digital Tibet market
随机推荐
MapReduce实现矩阵乘法–实现代码
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
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
Father and basketball
MyCms 自媒体商城 v3.4.1 发布,使用手册更新
Golang — 命令行工具cobra
Go language web development series 28: solve cross domain access of CORS with gin contrib / CORS
PhpMyAdmin stage file contains analysis traceability
SQL Injection (AJAX/JSON/jQuery)
[today in history] July 3: ergonomic standards act; The birth of pioneers in the field of consumer electronics; Ubisoft releases uplay
SQL Injection (GET/Search)
[sort] bucket sort
软件测试工作那么难找,只有外包offer,我该去么?
Resource Cost Optimization Practice of R & D team
Leetcode-1175.Prime Arrangements
记录关于银行回调post请求405 问题
GoLand 2021.1.1: configure the multi line display of the tab of the open file
研发团队资源成本优化实践
CVPR 2022 | interpretation of 6 excellent papers selected by meituan technical team
Start signing up CCF C ³- [email protected] chianxin: Perspective of Russian Ukrainian cyber war - Security confrontation and sanctions g