1.
头文件
#ifndef MYWIDGET_H
#define MYWIDGET_H
#include <QWidget>
#include <QMovie>
#include <QTextEdit>
#include <QDebug>
namespace Ui {
class MyWidget;
}
class MyWidget : public QWidget
{
Q_OBJECT
public:
explicit MyWidget(QWidget *parent = nullptr);
~MyWidget();
private:
Ui::MyWidget *ui;
public slots:
void my_close();
void login_slot();
};
#endif // MYWIDGET_H
main.cpp
#include "mywidget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MyWidget w;
w.show();
return a.exec();
}
mywidget.cpp
#include "mywidget.h"
#include "ui_mywidget.h"
MyWidget::MyWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::MyWidget)
{
ui->setupUi(this);
//创建动图对象
QMovie *mv = new QMovie(":/pictrue/pic1.gif");
//加入标签
ui->logo_lab->setMovie(mv);
//启动动图
mv->start();
//自动适应大小
ui->logo_lab->setScaledContents(true);
//加入图片
ui->username_lab->setPixmap(QPixmap(":/pictrue/userName.jpg"));
//自动适应大小
ui->username_lab->setScaledContents(true);
ui->passwd_lab->setPixmap(QPixmap(":/pictrue/passwd.jpg"));
ui->passwd_lab->setScaledContents(true);
//设置占位
ui->username_edit->setPlaceholderText("账号/邮箱/手机");
ui->passwd_edti->setPlaceholderText("密码");
//设置密码输入
ui->passwd_edti->setEchoMode(QLineEdit::Password);
//=======================信号和槽=========================
//手动连接,qt4版本,取消按钮自定义槽函数关闭窗口
connect(ui->cancel_btn,SIGNAL(clicked()),this,SLOT(my_close()));
//手动连接,qt5版本
connect(ui->login_btn,&QPushButton::clicked,this,&MyWidget::login_slot);
}
MyWidget::~MyWidget()
{
delete ui;
}
//手动连接自定义槽函数,qt4版本,关闭窗口
void MyWidget::my_close()
{
this->close();
}
//手动连接自定义槽函数,qt5版本,登录
void MyWidget::login_slot()
{
if(ui->username_edit->text() == "admin" & ui->passwd_edti->text() == "123456")
{
qDebug() << "登录成功";
}else {
qDebug() << "登录失败";
ui->passwd_edti->clear(); //登录失败清空密码栏
}
}
效果图
2
2.思维导图