#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);//设置账户和密码的登录标签ui->lab1->setPixmap(QPixmap(":/pictrue/wodepeizhenshi.png"));ui->lab1->setScaledContents(true);ui->lab2->setPixmap(QPixmap(":/pictrue/passwd.jpg"));ui->lab2->setScaledContents(true);//设置密码ui->lin2->setEchoMode(QLineEdit::Password);//设置动图QMovie *mv=new QMovie(":/pictrue/82a8d3fd16b153d6.gif");ui->lab0->setMovie(mv);mv->start();ui->lab0->setScaledContents(true);//设置“取消”按钮connect(ui->cancel,SIGNAL(clicked()),this,SLOT(my_solt()));//设置“登录”按钮connect(ui->login,&QPushButton::clicked,this,&Widget::my_solt1);}Widget::~Widget()
{delete ui;
}
void Widget::my_solt()
{this->close();
}
void Widget::my_solt1()
{if(ui->lin1->text() == "admin" && ui->lin2->text() == "123456"){num=0;this->close();}else {num=1;ui->lin2->setText("");}Widget1 *s = new Widget1;s->show();
}
Widget1::Widget1(QWidget *parent): QWidget(parent)
{if(num==0){QLabel *lab = new QLabel("登录成功!");lab->setParent(this);this->resize(100,100);lab->resize(100,100);}else if(num == 1){QLabel *lab = new QLabel("登录失败!");lab->setParent(this);this->resize(100,100);lab->resize(100,100);}
}
Widget1::~Widget1()
{}
登录成功
将自动关闭窗口,并且打开一个窗口显示登录成功
登录失败
会打开一个窗口显示登录失败,并且清空密码