随笔 - 632  文章 - 17  评论 - 54  阅读 - 93万

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()
{
}
复制代码

 

posted on   飘杨......  阅读(50)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
历史上的今天:
2021-12-22 Qt创建一个按钮,点击按钮关闭窗口
2013-12-22 Java设置以及获取JavaBean私有属性进阶
2013-12-22 Java使用PropertyDescriptor获取实体类中私有属性的值,并给私有属性赋值
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示