当前位置:网站首页>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 是嵌入式产品中 最常用的布局方式
边栏推荐
- Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
- Go 1.16.4: manage third-party libraries with Mod
- Error running 'application' in idea running: the solution of command line is too long
- Go language unit test 4: go language uses gomonkey to test functions or methods
- Go language web development series 27: Gin framework: using gin swagger to implement interface documents
- Brief analysis of tensorboard visual processing cases
- SwiftUI 开发经验之作为一名程序员需要掌握的五个最有力的原则
- 编程内功之编程语言众多的原因
- Spark practice 1: build spark operation environment in single node local mode
- Kivy教程之 盒子布局 BoxLayout将子项排列在垂直或水平框中(教程含源码)
猜你喜欢
刚毕业的欧洲大学生,就能拿到美国互联网大厂 Offer?
Go language web development series 26: Gin framework: demonstrates the execution sequence of code when there are multiple middleware
全面发展数字经济主航道 和数集团积极推动UTONMOS数藏市场
Ocean CMS vulnerability - search php
TensorBoard可视化处理案例简析
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
The solution of Chinese font garbled code in keil5
双向链表(我们只需要关注插入和删除函数)
When updating mysql, the condition is a query
AI 考高数得分 81,网友:AI 模型也免不了“内卷”!
随机推荐
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
[quantitative trading] permanent portfolio, turtle trading rules reading, back testing and discussion
[技术发展-24]:现有物联网通信技术特点
Flutter dynamic | fair 2.5.0 new version features
双链笔记 RemNote 综合评测:快速输入、PDF 阅读、间隔重复/记忆
Mobile phones and computers can be used, whole people, spoof code connections, "won't you Baidu for a while" teach you to use Baidu
The solution of Chinese font garbled code in keil5
Go: send the get request and parse the return JSON (go1.16.4)
TensorBoard可视化处理案例简析
掌握Cypress命令行选项,是真正掌握Cypress的基础
挡不住了,国产芯片再度突进,部分环节已进到4nm
JS 将伪数组转换成数组
Go language unit test 4: go language uses gomonkey to test functions or methods
【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明
Start signing up CCF C ³- [email protected] chianxin: Perspective of Russian Ukrainian cyber war - Security confrontation and sanctions g
Unity render streaming communicates with unity through JS
SQL Injection (GET/Search)
Static linked list (subscript of array instead of pointer)
Unity embeddedbrowser browser plug-in event communication
MySQL 数据处理值增删改