当前位置:网站首页>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 是嵌入式产品中 最常用的布局方式
边栏推荐
- The principle of human voice transformer
- SQL Injection (AJAX/JSON/jQuery)
- 双链笔记 RemNote 综合评测:快速输入、PDF 阅读、间隔重复/记忆
- Unable to stop it, domestic chips have made another breakthrough, and some links have reached 4nm
- php 迷宫游戏
- PhpMyAdmin stage file contains analysis traceability
- [sort] bucket sort
- Replace the GPU card number when pytorch loads the historical model, map_ Location settings
- Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
- 顺序表(C语言实现)
猜你喜欢
KEIL5出现中文字体乱码的解决方法
Flutter dynamic | fair 2.5.0 new version features
使用vscode查看Hex或UTF-8编码
Kivy教程之 盒子布局 BoxLayout将子项排列在垂直或水平框中(教程含源码)
Box layout of Kivy tutorial BoxLayout arranges sub items in vertical or horizontal boxes (tutorial includes source code)
3D视觉——2.人体姿态估计(Pose Estimation)入门——OpenPose含安装、编译、使用(单帧、实时视频)
研发团队资源成本优化实践
Unable to stop it, domestic chips have made another breakthrough, and some links have reached 4nm
Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:
When updating mysql, the condition is a query
随机推荐
Father and basketball
项目协作的进度如何推进| 社区征文
JSON serialization case summary
User and group command exercises
Several common optimization methods matlab principle and depth analysis
Open PHP error prompt under Ubuntu 14.04
CVPR 2022 | 美团技术团队精选6篇优秀论文解读
[技术发展-24]:现有物联网通信技术特点
Students who do not understand the code can also send their own token, which is easy to learn BSC
软件测试工作那么难找,只有外包offer,我该去么?
Go language unit test 5: go language uses go sqlmock and Gorm to do database query mock
[机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心
The principle of human voice transformer
SQL Injection (POST/Select)
GoLand 2021.1: rename the go project
Kivy tutorial how to load kV file design interface by string (tutorial includes source code)
PhpMyAdmin stage file contains analysis traceability
Flutter动态化 | Fair 2.5.0 新版本特性
[développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes
又一个行业被中国芯片打破空白,难怪美国模拟芯片龙头降价抛售了