QTday3

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //设置窗口
    this->setWindowTitle("GTA5");
    this->setWindowIcon(QIcon(":/pictrue/gta.jfif"));
    this->setWindowFlags(Qt::FramelessWindowHint);


    //设置标签
    //整个背景
    ui->lab1->setPixmap(QPixmap(":/pictrue/gta_login.jpg"));
    ui->lab1->setScaledContents(true);

    //R星logo
    ui->lab2->setPixmap(QPixmap(":/pictrue/rxing.png"));
    ui->lab2->setScaledContents(true);
    ui->lab2->setStyleSheet("border-radius:10px");

    ui->lab3->setPixmap(QPixmap(":/pictrue/denglu.webp"));
    ui->lab4->setPixmap(QPixmap(":/pictrue/passwd.jpg"));
    ui->lab3->setScaledContents(true);
    ui->lab4->setScaledContents(true);

    //设置行编辑器
    ui->edit1->setPlaceholderText("账号/邮箱");
    ui->edit2->setPlaceholderText("密码");
    ui->edit2->setEchoMode(QLineEdit::Password);

    //QT4手动关闭槽函数
   // connect(ui->btn2,SIGNAL(clicked()),this,SLOT(close()));

    //QT5手动关闭槽函数
    connect(ui->btn1,&QPushButton::clicked,this,&Widget::btn1_slot);


}

Widget::~Widget()
{
    delete ui;
}


void Widget::btn1_slot()
{
    if(ui->edit1->text()=="123"&&ui->edit2->text()=="123456")
    {
        QMessageBox msg(QMessageBox::Information,
                        "提示",
                        "登录成功",
                        QMessageBox::Yes,
                        this);
       int ret= msg.exec();
       if(ret==QMessageBox::Yes)
       {
           this->close();//关闭
           emit this->my_jump();//跳转
       }
    }
    else
    {
        QMessageBox msg(QMessageBox::Warning,
                        "警告",
                        "账号和密码不匹配,是否重新登录",
                        QMessageBox::Yes|QMessageBox::No,
                        this);
        int ret=msg.exec();
        if(ret==QMessageBox::Yes)
        {
             ui->edit2->clear();//清空密码框
        }
        else
        {
            this->close();//关闭界面
        }
    }

}



void Widget::on_btn2_clicked()
{
    int ret=QMessageBox::question(this,
                                  "问题",
                                  "您确定要退出登录吗?",
                                  QMessageBox::Yes|QMessageBox::No);
    if(ret==QMessageBox::Yes)
    {
         this->close();//关闭界面
    }

}

你可能感兴趣的:(qt)