头文件
#ifndef WIDGET_H
#define WIDGET_H
#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();
private slots:
void on_login_clicked();
private:
Ui::Widget *ui;
};
#endif
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
源文件
#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(":/res/1.gif"));
QMovie *mv = new QMovie(":/res/1.gif");
ui->logoLab->setMovie(mv);
mv->start();
ui->logoLab->setScaledContents(true);
ui->userLab->resize(40,40);
ui->userLab->setPixmap(QPixmap(":/res/preview.gif"));
ui->userLab->setScaledContents(true);
ui->passLab->resize(40,40);
ui->passLab->setPixmap(QPixmap(":/res/preview.gif"));
ui->passLab->setScaledContents(true);
ui->userEdit->setPlaceholderText("请输入账号");
ui->passEdit->setPlaceholderText("请输入密码");
ui->passEdit->setEchoMode(QLineEdit::Password);
ui->login->setIcon(QIcon(":/res/preview.gif"));
ui->cancel->setIcon(QIcon(":/res/preview.gif"));
connect(ui->cancel,SIGNAL(clicked()),this,SLOT(close()));
connect(this,&Widget::my_signal,[&](){
if(ui->userEdit->text()=="" || ui->passEdit->text()=="")
{
qDebug() << "账号或密码为空";
}else{
if(ui->userEdit->text()=="admin")
{
if(ui->passEdit->text()=="123456")
{
qDebug() << "登录成功";
this->close();
}else
{
qDebug() << "密码错误,请重新输入";
ui->passEdit->clear();
}
}else{
qDebug() << "账号不存在";
}
}
});
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_login_clicked()
{
emit my_signal();
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
思维导图