QFormLayout表单布局
一、概述
新建一个简单的登录表单布局QFormLayout。如下:
二、代码示例
#include "FormLayoutExampleWindow.h" FormLayoutExampleWindow::FormLayoutExampleWindow(QWidget* parent) : QWidget(parent) { this->setWindowTitle("Form表单"); //表单布局 EditText* edtUserName = new EditText; edtUserName->setPlaceholderText("请输入用户名"); edtUserName->setFixedSize(150, 30); EditText* edtPassword = new EditText; edtPassword->setPlaceholderText("请输入密码"); edtPassword->setFixedSize(150, 30); edtPassword->setEchoMode(EditText::Password); Button* btnLogin = new Button; btnLogin->setFixedSize(100, 40); btnLogin->setText("登录"); QFormLayout* formLayout = new QFormLayout(this); formLayout->addRow("用户名:", edtUserName); formLayout->addRow("密 码:", edtPassword); formLayout->addRow(btnLogin); formLayout->setSpacing(10); formLayout->setMargin(50); formLayout->setAlignment(btnLogin, Qt::AlignRight); this->setLayout(formLayout); formLayout->setFormAlignment(Qt::AlignCenter); formLayout->setAlignment(Qt::AlignCenter); connect(btnLogin, &Button::clicked, [=]() { QString userName = edtUserName->text(); QString password = edtPassword->text(); if (userName.isEmpty()) { QString dlgTitle = "温馨提示"; QString strInfo = "用户名不能为空?"; QMessageBox::StandardButton result = QMessageBox::information(this, dlgTitle, strInfo, QMessageBox::Ok); return; } else if (password.isEmpty()) { QString dlgTitle2 = "温馨提示"; QString strInfo2 = "用户密码不能为空?"; QMessageBox::StandardButton result2 = QMessageBox::information(this, dlgTitle2, strInfo2, QMessageBox::Ok); return; } QString dlgTitle3 = "温馨提示"; QString strInfo3 = "登录成功"; QMessageBox::StandardButton result2 = QMessageBox::information(this, dlgTitle3, strInfo3, QMessageBox::Ok); }); } FormLayoutExampleWindow::~FormLayoutExampleWindow() { }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
2021-12-22 Qt创建一个按钮,点击按钮关闭窗口
2013-12-22 Java设置以及获取JavaBean私有属性进阶
2013-12-22 Java使用PropertyDescriptor获取实体类中私有属性的值,并给私有属性赋值