💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
[TOC] ## 概述 QFormLayout管理输入型控件和关联的标签组成的那些Form表单 QFormLayout::RowWrapPolicy枚举 |内容| 值| 描述 效果| |---|---|---| |QFormLayout::DontWrapRows |0| 输入框始终在标签旁边 这里写图片描述| |QFormLayout::WrapLongRows |1| 标签有足够的空间适应,如果最小大小比可用空间大,输入框会被换到下一行 这里写图片描述| |QFormLayout::WrapAllRows |2 |输入框始终在标签下边 这里写图片描述| ## 示例 ### Simple ``` QFormLayout *pLayout = new QFormLayout(); pLayout->addRow(QStringLiteral("用户名:"), pUserLineEdit); pLayout->addRow(QStringLiteral("密码:"), pPasswordLineEdit); pLayout->addRow(QStringLiteral("验证码:"), pVerifyLineEdit); pLayout->setSpacing(10); pLayout->setMargin(10); setLayout(pLayout); ``` 与QGridLayout比较 ``` QLabel *pUserNameLabel = new QLabel(this); QLabel *pPasswordLabel = new QLabel(this); QLabel *pVerifyLabel = new QLabel(this); pUserNameLabel->setText(QStringLiteral("用户名:")); pPasswordLabel->setText(QStringLiteral("密码:")); pVerifyLabel->setText(QStringLiteral("验证码:")); QGridLayout *pLayout = new QGridLayout(); pLayout->addWidget(pUserNameLabel, 0, 0); pLayout->addWidget(pUserLineEdit, 0, 1); pLayout->addWidget(pPasswordLabel, 1, 0); pLayout->addWidget(pPasswordLineEdit, 1, 1); pLayout->addWidget(pVerifyLabel, 2, 0); pLayout->addWidget(pVerifyLineEdit, 2, 1); pLayout->setSpacing(10); pLayout->setMargin(10); setLayout(pLayout); ```