10.8 Qt登录界面

cpp 复制代码
#include "widget.h"
#include <QMessageBox>
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent),neww(nullptr)
{
    this->setWindowTitle("Plane");
    this->setWindowIcon(QIcon(":/picture/111.png"));
    btn1=new QPushButton;

    this->setFixedSize(640,480);
    btn1->setParent(this);   //将界面设置为父组件
    btn1->setText("登录");    //设置按钮文本
    btn1->move(200,350);
    btn1->resize(120,40);
    btn1->setStyleSheet("color:white;background-color:skyblue;border-radius:10px;"); //设置按钮样式表
    btn1->setObjectName("btn1");

    btn2=new QPushButton(this);
    btn2->setText("取消");
    btn2->move(btn1->x()+btn1->width()+20,btn1->y());
    btn2->resize(btn1->size());
    btn2->setStyleSheet("background-color:white;border-radius:10px;");

    acc =new QLineEdit(this);
    acc->resize(260,30);
    acc->move(200,250);
    acc->setAlignment(Qt::AlignCenter);  //文本居中显示
    acc->setEchoMode(QLineEdit::Normal); //设置文本显示模式
    acc->setPlaceholderText("请输入账号"); //设置占位文本

    pwd =new QLineEdit(this);
    pwd->resize(acc->size());
    pwd->move(acc->x(),acc->y()+acc->height()+20);
    pwd->setEchoMode(QLineEdit::Password);
    pwd->setPlaceholderText("请输入密码");
    pwd->setAlignment(Qt::AlignCenter);

    QLabel *logo=new QLabel;
    logo->setParent(this);
    logo->resize(150,150);
    logo->setPixmap(QPixmap(":/picture/111.png"));  //插入图片显示
    logo->setScaledContents(true);  //图片填充
    logo->move(250,60);

    QObject obj;
    //obj.connect(this->btn2,SIGNAL(clicked()),this,SLOT(close()));

    connect(btn1, &QPushButton::clicked, this, &Widget::on_btn1_clicked);
    connect(btn2, &QPushButton::clicked, this, &Widget::on_btn2_clicked);
}



Widget::~Widget()
{
}


void Widget::on_btn1_clicked() //登录按钮
{
    if(acc->text()==pwd->text())
    {                                        //基于属性
        QMessageBox msg(QMessageBox::NoIcon, //无图标对话框
                        "登录",   //对话框标题
                        "登录成功!", //对话框文本
                        QMessageBox::Ok, //提供的按钮
                        this); //父类指针
        int login=msg.exec();
        if(login==QMessageBox::Ok)
        {
            neww=new Second();
            neww->show();
            this->close();
        }
    }else if(acc->text()!=pwd->text())
    {
        QMessageBox fail(QMessageBox::Critical,
                         "登录失败",
                         "账号密码不匹配,是否重新输入?",
                         QMessageBox::Ok|QMessageBox::No,
                         this);
        int log=fail.exec();
        if(log==QMessageBox::Ok)
        {
            pwd->clear();
        }else if(log==QMessageBox::No)
        {
            this->close();
        }
    }
}


void Widget::on_btn2_clicked()
{
    QMessageBox::StandardButton flag;         //基于静态成员函数
    flag=QMessageBox::question(this,
                               "退出",
                               "是否退出?",
                               QMessageBox::Ok|QMessageBox::No,
                               QMessageBox::No);  //默认选中的按钮
    if(flag==QMessageBox::Ok)
    {
        this->close();
    }
}
相关推荐
fobwebs几秒前
wordpress 网站安装了Yoast SEO,并且做了内容的优化后,如果想重置Yoast SEO,并且删除所有的优化内容,应该如何操作?
数据库·yoast seo·重置yoast seo·清空yoast seo内容
程序员小寒几秒前
JavaScript设计模式(四):发布-订阅模式实现与应用
开发语言·前端·javascript·设计模式
csbysj2020几秒前
JSON 语法
开发语言
郝学胜-神的一滴3 分钟前
深入解析:生成器在UserList中的应用与Python可迭代对象实现原理
开发语言·python·程序人生·算法
为美好的生活献上中指4 分钟前
*Java 沉淀重走长征路*之——《Linux 从入门到企业实战:一套六步法,带你打通运维与开发的任督二脉》
java·linux·运维·开发语言·阿里云·华为云·linux命令
wuqingshun3141598 分钟前
依赖注入的方式有几种,各是什么?
java·开发语言
路由侠内网穿透17 分钟前
本地部署开源 LLM 应用观测与调试平台 Langfuse 并实现外部访问
运维·服务器·数据库·物联网·开源
SPC的存折17 分钟前
1、Ansible之Ansible安装与入门
linux·数据库·ansible
qiumingxun22 分钟前
mysql的分区表
数据库·mysql
sxhcwgcy23 分钟前
Spring Boot中集成MyBatis操作数据库详细教程
数据库·spring boot·mybatis