1.头文件
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QDebug>
#include <QMovie>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
private slots:
void login();
private:
Ui::Widget *ui;
};
#endif // WIDGET_H
2.源文件
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
this->setWindowFlag(Qt::FramelessWindowHint);
ui->setupUi(this);
ui->logolab->setPixmap(QPixmap(":/pictrue/5.png"));
ui->logolab->setScaledContents(true);
ui->passwdlab->setPixmap(QPixmap(":/pictrue/2.jpg"));
ui->passwdlab->setScaledContents(true);
ui->userlab->setPixmap(QPixmap(":/pictrue/6.jpg"));
ui->userlab->setScaledContents(true);
QMovie *mv = new QMovie(":/pictrue/4.gif");
ui->lab1->setMovie(mv);
mv->start();
ui->lab1->setScaledContents(true);
QMovie *mv1 = new QMovie(":/pictrue/6.gif");
ui->lab2->setMovie(mv1);
mv1->start();
ui->lab2->setScaledContents(true);
ui->passwdedit->setEchoMode(QLineEdit::Password);
//qt4 实现取消按钮关闭窗口
connect(ui->cancelbtn,SIGNAL(clicked()),this,SLOT(close()));
//qt5
connect(ui->dengbtn,&QPushButton::clicked,this,&Widget::login);
}
Widget::~Widget()
{
delete ui;
}
void Widget::login()
{
if(ui->useredit->text() == "admin" && ui->passwdedit->text() == "123456")
{
qDebug() << "登陆成功" ;
this->close();
}
else
{
ui->passwdedit->clear();
qDebug() <<"登陆失败";
}
}