作业
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QDebug>
#include <QIcon> //图标类
#include <QPushButton> //按钮类
#include <QLabel> //标签类
#include <QMovie> //动画类
#include <QLineEdit> //行编译器类
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;
QLabel *labe1;
QLabel *labe2;
QLabel *labe3;
QLineEdit *zhanghao;
QLineEdit *mima;
};
#endif // WIDGET_H
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
this->resize(430,300);
//按钮1
btn1 = new QPushButton("登录",this);
btn1->resize(110,35);
btn1->move(100,240);
//将自定义组件连接到函数中
connect(btn1,&QPushButton::clicked,[&](){
if(zhanghao->text() == mima->text())
{
qDebug()<<"登录成功";
this->close();
}else
{
qDebug()<<"登录失败";
mima->clear();
}
});
//按钮2
btn2 = new QPushButton("取消",this);
btn2->resize(110,35);
btn2->move(btn1->x()+btn1->width()+20,btn1->y());
connect(btn2,&QPushButton::clicked,[&](){
this->close();
});
//输入框1
mima = new QLineEdit(this);
mima->resize(210,30);
mima->move(130,200);
mima->clear(); //清空内容
mima->setPlaceholderText("密码"); //设置占位文本
mima->setEchoMode(QLineEdit::Password); //设置回显模式
//输入框2
zhanghao = new QLineEdit(this);
zhanghao->resize(210,30);
zhanghao->move(mima->x(),mima->y()-mima->height()-10);
zhanghao->clear(); //清空内容
zhanghao->setPlaceholderText("账号"); //设置占位文本
//账号标签
labe1 = new QLabel("账号:",this);
labe1->resize(30,30);
labe1->move(zhanghao->x()-30,zhanghao->y());
labe1->setPixmap(QPixmap("C:\\Users\\Admin\\Desktop\\1\\pictrue\\pictrue\\userName.jpg"));
labe1->setScaledContents(true);
//密码标签
labe2 = new QLabel("密码:",this);
labe2->resize(30,30);
labe2->move(mima->x()-30,mima->y());
labe2->setPixmap(QPixmap("C:\\Users\\Admin\\Desktop\\1\\pictrue\\pictrue\\passwd.jpg"));
labe2->setScaledContents(true);
//动画标签
labe3 = new QLabel("动画",this);
labe3->resize(430,100);
QMovie *movie = new QMovie("C:\\Users\\Admin\\Desktop\\1\\pictrue\\pictrue\\zz.gif");
//将动图对象放入到标签中
labe3->setMovie(movie);
//让动图动起来
movie->start();
//让标签内容自适应图片大小
labe3->setScaledContents(true);
}
Widget::~Widget()
{
delete ui;
}