当前位置:网站首页>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 是嵌入式产品中 最常用的布局方式
边栏推荐
- MapReduce实现矩阵乘法–实现代码
- Swiftui development experience: the five most powerful principles that a programmer needs to master
- 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
- IBEM 数学公式检测数据集
- 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
- Go 1.16.4: purpose of go mod tidy
- 挡不住了,国产芯片再度突进,部分环节已进到4nm
- 树的深入和广度优先遍历(不考虑二叉树)
- Brief analysis of tensorboard visual processing cases
- Go language web development series 28: solve cross domain access of CORS with gin contrib / CORS
猜你喜欢
JVM系列——概述,程序计数器day1-1
Go language unit test 4: go language uses gomonkey to test functions or methods
[technology development-24]: characteristics of existing IOT communication technology
掌握Cypress命令行选项,是真正掌握Cypress的基础
GoLand 2021.2 configure go (go1.17.6)
SQL Injection (AJAX/JSON/jQuery)
Flutter dynamic | fair 2.5.0 new version features
Use docker to build sqli lab environment and upload labs environment, and the operation steps are provided with screenshots.
Logback log sorting
Flutter dynamic | fair 2.5.0 new version features
随机推荐
windos 创建cordova 提示 因为在此系统上禁止运行脚本
SwiftUI 开发经验之作为一名程序员需要掌握的五个最有力的原则
挡不住了,国产芯片再度突进,部分环节已进到4nm
Libuv Library - Design Overview (Chinese version)
[556. Next larger element III]
Conversion function and explicit
Mycms we media mall v3.4.1 release, user manual update
HALCON联合C#检测表面缺陷——HALCON例程autobahn
Stack application (balancer)
Go language web development series 30: gin: grouping by version for routing
JVM系列——概述,程序计数器day1-1
物联网毕设 --(STM32f407连接云平台检测数据)
SQL Injection (GET/Search)
使用vscode查看Hex或UTF-8编码
SQL Injection (AJAX/JSON/jQuery)
Go language web development series 27: Gin framework: using gin swagger to implement interface documents
[technology development-24]: characteristics of existing IOT communication technology
Error running 'application' in idea running: the solution of command line is too long
When updating mysql, the condition is a query
全面发展数字经济主航道 和数集团积极推动UTONMOS数藏市场