一、问题

image.png
解决方案:
(1)绝对定位组件的坐标和大小
(2)嵌套QBoxLayout
(3)创建3*2的QGridLayout
image.png

二、布局管理器

QformLayout布局管理器
以表单(Form)的方式管理界面组件
表单布局中的标签和组件是相互对应的关系
image.png
QFormLayout的用法概要
image.png
表单布局支持嵌套,其他布局管理器可以作为子布局被其管理。

三、编程实验 24-2.pro QformLayout的实现实例

#include "Widget.h"
#include <QLineEdit>
#include <QFormLayout>

Widget::Widget(QWidget *parent) : QWidget(parent, Qt::WindowCloseButtonHint)
{
    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::WrapLongRows);
    layout->setLabelAlignment(Qt::AlignRight);
    layout->setSpacing(10);

    setLayout(layout);
    setWindowTitle("FTP");
}

Widget::~Widget()
{
    
}

QFormLayout的样式函数
void setRowWrapPolicy(RowWrapPolicy,policy)
void setLabeLAlignment(Qt::Alignment alignment)

四、小结

QFormLayout以表单的方式管理界面组件
QFormLayout的样式设置简洁明了
QFormLayout支持的布局管理器相互嵌套
QFormLayout是嵌入式产品中最常用的布局方式


YingLi
6 声望4 粉丝

From zero to hero.