当前位置:网站首页>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 是嵌入式产品中 最常用的布局方式
边栏推荐
- [redis] cache warm-up, cache avalanche and cache breakdown
- Complete DNN deep neural network CNN training with tensorflow to complete image recognition cases
- 如何使用lxml判断网站公告是否更新
- Complete deep neural network CNN training with tensorflow to complete picture recognition case 2
- Golang — 命令行工具cobra
- JS convert pseudo array to array
- Father and basketball
- AI scores 81 in high scores. Netizens: AI model can't avoid "internal examination"!
- SwiftUI 开发经验之作为一名程序员需要掌握的五个最有力的原则
- 网上开户哪家证券公司佣金最低,我要开户,网上客户经理开户安全吗
猜你喜欢
The shortage of graphics cards finally came to an end: 3070ti for more than 4000 yuan, 2000 yuan cheaper than the original price, and 3090ti
Go language unit test 5: go language uses go sqlmock and Gorm to do database query mock
GoLand 2021.1: rename the go project
JVM系列——概述,程序计数器day1-1
Logback log sorting
PhpMyAdmin stage file contains analysis traceability
Flutter dynamic | fair 2.5.0 new version features
[how to solve FAT32 when the computer is inserted into the U disk or the memory card display cannot be formatted]
MySQL 数据增删改查综合案例
[technology development-24]: characteristics of existing IOT communication technology
随机推荐
Disruptor -- a high concurrency and high performance queue framework for processing tens of millions of levels
[today in history] July 3: ergonomic standards act; The birth of pioneers in the field of consumer electronics; Ubisoft releases uplay
[技术发展-24]:现有物联网通信技术特点
Kivy教程之 盒子布局 BoxLayout将子项排列在垂直或水平框中(教程含源码)
Heap structure and heap sort heapify
Conversion function and explicit
Go 1.16.4: manage third-party libraries with Mod
pytorch 载入历史模型时更换gpu卡号,map_location设置
SVN添加文件时的错误处理:…\conf\svnserve.conf:12: Option expected
Open PHP error prompt under Ubuntu 14.04
RichView TRVStyle ListStyle 列表样式(项目符号编号)
Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:
Record 405 questions about bank callback post request
Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
Several common optimization methods matlab principle and depth analysis
记录关于银行回调post请求405 问题
MySQL installation, uninstallation, initial password setting and general commands of Linux
Start signing up CCF C ³- [email protected] chianxin: Perspective of Russian Ukrainian cyber war - Security confrontation and sanctions g
Go language web development series 28: solve cross domain access of CORS with gin contrib / CORS
[bw16 application] instructions for firmware burning of Anxin Ke bw16 module and development board update