Widget.h
cpp
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QMovie>
#include <QPushButton>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
private:
Ui::Widget *ui;
QPushButton *Btn1;//登录按钮
QPushButton *Btn2;//取消按钮
public slots:
void my_Btn1_slot();
void my_Btn2_slot();
};
#endif // WIDGET_H
Widget.cpp
cpp
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
,Btn1(new QPushButton(this))
,Btn2(new QPushButton(this))
{
ui->setupUi(this);
ui->setupUi(this);
//设置背景图
QMovie *mv = new QMovie(":/pictrue/zz.gif");
ui->logoLab->setMovie(mv);
mv->start();
ui->logoLab->setScaledContents(true);
//设置账号密码前面图标
ui->usernameLab->setPixmap(QPixmap(":/pictrue/userName.jpg"));
ui->usernameLab->setScaledContents(true);
ui->passwdLab->setPixmap(QPixmap(":/pictrue/passwd.jpg"));
ui->passwdLab->setScaledContents(true);
//设置占位
ui->usernameEdit->setPlaceholderText("手机号/QQ号/邮箱");
ui->passwdEdit->setEchoMode(QLineEdit::Password);
ui->passwdEdit->setPlaceholderText("密码");
//qt4版本设置登录按钮
Btn1->setText("登录");
Btn1->resize(150,50);
Btn1->move(70,300);
Btn1->setStyleSheet("background-color:rgb(28,196,252)");
connect(Btn1,SIGNAL(clicked()),this,SLOT(my_Btn1_slot()));
//连接槽函数
//connect(Btn1,SIGNAL());
//qt4版本设置取消按钮
Btn2->setText("取消");
Btn2->resize(150,50);
Btn2->move(250,300);
Btn2->setStyleSheet("background-color:rgb(28,196,252)");
connect(Btn2,SIGNAL(clicked()),this,SLOT(my_Btn2_slot()));
}
void Widget::my_Btn2_slot()
{
this->close();
}
void Widget::my_Btn1_slot()
{
if(ui->usernameEdit->text() == "admin" && ui->passwdEdit->text() == "123456")
{
qDebug()<<"登录成功!";
this->close();
}
else
{
qDebug()<<"登录失败!";
ui->usernameEdit->clear();
ui->passwdEdit->clear();
}
}
Widget::~Widget()
{
delete ui;
}