10.19作业


widget.cpp

#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setWindowFlag(Qt::FramelessWindowHint);

    ui->logoLab->setPixmap(QPixmap(":/222/2222.gif"));
    QMovie *mv =  new QMovie(":/222/2222.gif");
    ui->logoLab->setMovie(mv);
    mv->start();
    ui->logoLab->setScaledContents(true);
    ui->userLab->setPixmap(QPixmap(":/222/ddk.jpg"));
    ui->userLab->setScaledContents(true);
    ui->passLab->setPixmap(QPixmap(":/222/kl.jpg"));
    ui->passLab->setScaledContents(true);
    ui->userEdit->setPlaceholderText("请输入账号");
    ui->passEdit->setPlaceholderText("请输入密码");
    ui->passEdit->setEchoMode(QLineEdit::Password);
    ui->login->setIcon(QIcon(""));
    ui->cancel->setIcon(QIcon(""));
    connect(ui->cancel,SIGNAL(clicked()),this,SLOT(close()));
    connect(this,&Widget::my_signal,[&]()
    {
        if(ui->userEdit->text()=="admin")
        {
            if(ui->passEdit->text()=="123456")
            {
                ui->userEdit->clear();
                ui->passEdit->clear();
                //提示登录成功
             QMessageBox::information(this, "提示", "登录成功");
                this->close();
                //跳转
                emit jump();
            }
            else
            {
                //提示错误
                int ret = QMessageBox::critical(this, "错误", "账号和密码不匹配,是否重新登录", QMessageBox::Yes | QMessageBox::No);
                if(ret == QMessageBox::Yes)
                        ui->passEdit->clear();
                else
                    this->close();
            }
        }
    });
}
Widget::~Widget()
{
    delete ui;
}
void Widget::on_login_clicked()
{
    emit my_signal();
}
void Widget::jumpSlot()
{
    this->show();
}

second.cpp

#include "second.h"
#include "ui_second.h"
Second::Second(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Second)
{
    ui->setupUi(this);

    this->setWindowFlag(Qt::FramelessWindowHint);
    ui->lab->setPixmap(QPixmap(":/222/R-C.gif"));
    QMovie *mv =  new QMovie(":/222/R-C.gif");
    ui->lab->setMovie(mv);
    mv->start();
    ui->lab->setScaledContents(true);
}
Second::~Second()
{
    delete ui;
}
void Second::jumpSlot()
{
    this->show();
}
void Second::on_btn_clicked()
{
    int ret = QMessageBox::question(this, "询问", "是否要退出登录", QMessageBox::Yes | QMessageBox::No);
    if(ret == QMessageBox::Yes )
    {
        this->close();
        emit jump();
    }
    else
        this->show();
}

widget.h

#ifndef WIDGET_H
#define WIDGET_H
#include 
#include 
#include 
#include 
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
class Widget : public QWidget
{
    Q_OBJECT
public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
signals:
    void my_signal();
    void jump();
public slots:
    void jumpSlot();
private slots:
    void on_login_clicked();
private:
    Ui::Widget *ui;
};
#endif // WIDGET_H

second.h

#ifndef SECOND_H
#define SECOND_H
#include 
#include 
#include 
#include 
namespace Ui {
class Second;
}
class Second : public QWidget
{
    Q_OBJECT
public:
    explicit Second(QWidget *parent = nullptr);
    ~Second();
signals:
    void jump();
public slots:
    void jumpSlot();
private slots:
    void on_btn_clicked();
private:
    Ui::Second *ui;
};
#endif // SECOND_H

你可能感兴趣的:(qt)