当前位置:网站首页>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 是嵌入式产品中 最常用的布局方式
边栏推荐
- 服务器硬盘冷迁移后网卡无法启动问题
- [technology development-24]: characteristics of existing IOT communication technology
- SwiftUI 开发经验之作为一名程序员需要掌握的五个最有力的原则
- RichView TRVStyle ListStyle 列表样式(项目符号编号)
- 使用vscode查看Hex或UTF-8编码
- SQL Injection (GET/Search)
- JS 将伪数组转换成数组
- Golang - command line tool Cobra
- 【电脑插入U盘或者内存卡显示无法格式化FAT32如何解决】
- When updating mysql, the condition is a query
猜你喜欢
研发团队资源成本优化实践
CVPR 2022 | 美团技术团队精选6篇优秀论文解读
8 Queen question
When updating mysql, the condition is a query
Complete DNN deep neural network CNN training with tensorflow to complete image recognition cases
挡不住了,国产芯片再度突进,部分环节已进到4nm
Flutter动态化 | Fair 2.5.0 新版本特性
Kivy教程之 盒子布局 BoxLayout将子项排列在垂直或水平框中(教程含源码)
3D视觉——2.人体姿态估计(Pose Estimation)入门——OpenPose含安装、编译、使用(单帧、实时视频)
GoLand 2021.2 configure go (go1.17.6)
随机推荐
服务器硬盘冷迁移后网卡无法启动问题
使用vscode查看Hex或UTF-8编码
untiy世界边缘的物体阴影闪动,靠近远点的物体阴影正常
Use and design of Muduo buffer class
Go language unit test 4: go language uses gomonkey to test functions or methods
Go 1.16.4: purpose of go mod tidy
HALCON联合C#检测表面缺陷——HALCON例程autobahn
Mastering the cypress command line options is the basis for truly mastering cypress
MyCms 自媒体商城 v3.4.1 发布,使用手册更新
Unity embeddedbrowser browser plug-in event communication
Depth and breadth first traversal of tree (regardless of binary tree)
又一个行业被中国芯片打破空白,难怪美国模拟芯片龙头降价抛售了
JVM系列——概述,程序计数器day1-1
Error running 'application' in idea running: the solution of command line is too long
如何使用lxml判断网站公告是否更新
树的深入和广度优先遍历(不考虑二叉树)
Flutter动态化 | Fair 2.5.0 新版本特性
【被动收入如何挣个一百万】
MySQL 数据处理值增删改
Go: send the get request and parse the return JSON (go1.16.4)