当前位置:网站首页>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 是嵌入式产品中 最常用的布局方式
边栏推荐
- 项目协作的进度如何推进| 社区征文
- Leetcode-1175.Prime Arrangements
- Sequence table (implemented in C language)
- 【被动收入如何挣个一百万】
- 3D视觉——2.人体姿态估计(Pose Estimation)入门——OpenPose含安装、编译、使用(单帧、实时视频)
- Kivy教程之 如何通过字符串方式载入kv文件设计界面(教程含源码)
- Spark practice 1: build spark operation environment in single node local mode
- Mobile phones and computers can be used, whole people, spoof code connections, "won't you Baidu for a while" teach you to use Baidu
- Students who do not understand the code can also send their own token, which is easy to learn BSC
- Which securities company has the lowest Commission for opening an account online? I want to open an account. Is it safe for the online account manager to open an account
猜你喜欢

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

物联网毕设 --(STM32f407连接云平台检测数据)
![[today in history] July 3: ergonomic standards act; The birth of pioneers in the field of consumer electronics; Ubisoft releases uplay](/img/18/b06e2e5a2f76dc2da1c2374b8424b3.png)
[today in history] July 3: ergonomic standards act; The birth of pioneers in the field of consumer electronics; Ubisoft releases uplay

KEIL5出现中文字体乱码的解决方法

Mastering the cypress command line options is the basis for truly mastering cypress

This math book, which has been written by senior ml researchers for 7 years, is available in free electronic version

Conversion function and explicit

Go language web development series 27: Gin framework: using gin swagger to implement interface documents

Go: send the get request and parse the return JSON (go1.16.4)

User and group command exercises
随机推荐
JS convert pseudo array to array
The shadow of the object at the edge of the untiy world flickers, and the shadow of the object near the far point is normal
Flutter dynamic | fair 2.5.0 new version features
Flutter动态化 | Fair 2.5.0 新版本特性
HALCON联合C#检测表面缺陷——HALCON例程autobahn
Start signing up CCF C ³- [email protected] chianxin: Perspective of Russian Ukrainian cyber war - Security confrontation and sanctions g
Mobile phones and computers can be used, whole people, spoof code connections, "won't you Baidu for a while" teach you to use Baidu
Field problems in MySQL
Error handling when adding files to SVN:.... \conf\svnserve conf:12: Option expected
研发团队资源成本优化实践
使用vscode查看Hex或UTF-8编码
Windos creates Cordova prompt because running scripts is prohibited on this system
【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明
Complete deep neural network CNN training with tensorflow to complete picture recognition case 2
刚毕业的欧洲大学生,就能拿到美国互联网大厂 Offer?
Asp. Net core1.1 without project JSON, so as to generate cross platform packages
SQL Injection (POST/Search)
Unity EmbeddedBrowser浏览器插件事件通讯
SQL Injection (GET/Select)
树的深入和广度优先遍历(不考虑二叉树)