Widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QMovie>
#include <QPushButton>
#include <QTextToSpeech>
#include <QDebug>
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(); //信号函数的声明
public slots: //表示该权限下的函数,都是槽函数
void my_slot(); //槽函数的声明
void login_slot();
private:
Ui::Widget *ui;
};
#endif // WIDGET_H
Main.cpp
#include "widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
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);//设置纯净标题
QMovie *mv=new QMovie(":/Camera Roll/dd.jpg");
ui->logo->setMovie(mv);//将动图设置到标签中
mv->start();//动图动起来
ui->logo->setScaledContents(true);//自适应大小
ui->namelabel->setPixmap(QPixmap(":/Camera Roll/userName.jpg"));
ui->namelabel->setScaledContents(true);
ui->passwdlabel->setPixmap(QPixmap(":/Camera Roll/passwd.jpg"));
ui->passwdlabel->setScaledContents(true);
ui->nameline->setPlaceholderText("QQ号码/手机/邮箱");//设置占位
ui->passwdline->setPlaceholderText("密码");//设置占位
ui->passwdline->setEchoMode(QLineEdit::Password);
//连接自定义槽函数
connect(ui->cancel,SIGNAL(clicked()),this,SLOT(my_slot()));//连接
connect(ui->login,&QPushButton::clicked,this,&Widget::login_slot);
}
Widget::~Widget()
{
delete ui;
}
void Widget::my_slot()
{
this->close();
}
void Widget::login_slot()
{
if(ui->nameline->text()=="admin" && ui->passwdline->text()=="123456")
{
qDebug() << "登录成功";
this->close();
}
else
{
qDebug() << "登录失败";
ui->nameline->clear();
ui->passwdline->clear();
}
}
结果