复制代码
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget),
btn2(new QPushButton("注册",this)),
btn3(new QPushButton("登录",this)),
lab4(new QLabel(this))
{
ui->setupUi(this);
//-------------窗口相关设置----------------
this->setWindowTitle("用户登录"); //窗口标题
this->setWindowIcon(QIcon(":/pictrue/jye.png")); //窗口图标
this->resize(510,531); //重设窗口大小
this->setFixedSize(510,531); //固定窗口大小
//this->setWindowFlag(Qt::FramelessWindowHint); //隐藏头部
//this->setStyleSheet("background-color:white");
this->lower();
//-------------标签相关设置----------------
QMovie *mv = new QMovie(":/pictrue/longmao.gif");
ui->loginlab->setMovie(mv); //将动图设置到标签中
mv->start(); //让动图动起来
ui->loginlab->setScaledContents(true); //让图自动适应
QMovie *mv2 = new QMovie(":/pictrue/gongqijun.gif");
lab4->setMovie(mv2); //将动图设置到标签中
lab4->move(0,221);
lab4->resize(510,440);
lab4->lower();
mv2->start(); //让动图动起来
lab4->setScaledContents(true); //让图自动适应
//----------------------------------------------
ui->usernamelab->setPixmap(QPixmap(":/pictrue/R-C.png"));
ui->usernamelab->setScaledContents(true);
ui->passwdlab->setPixmap(QPixmap(":/pictrue/passwd.jpg"));
ui->passwdlab->setScaledContents(true);
//-------------行编译器相关设置----------------
ui->usernameEdit->setPlaceholderText("用户名");
ui->passwdEdit->setPlaceholderText("设置密码");
ui->passwdEdit->setEchoMode(QLineEdit::Password);
//-------------按钮设置----------------
btn2->move(ui->passwdlab->x(),ui->passwdlab->y()+ui->passwdlab->height()+70); //移动取消与登录的坐标位置,并重设大小
btn2->resize(101,51);
btn2->setStyleSheet("5px");
btn3->move(ui->passwdlab->x()+ui->passwdlab->width()+170,ui->passwdlab->y()+ui->passwdlab->height()+70);
btn3->resize(101,51);
btn3->setStyleSheet("5px");
connect(btn3,SIGNAL(clicked()),this,SLOT(my_slots()));
}
Widget::~Widget()
{
delete ui;
}
void Widget::my_slots()
{
if(ui->usernameEdit->text() == "admin" && ui->passwdEdit->text() == "123456")
{
qDebug("登录成功");
}
else
{
qDebug("登陆失败");
ui->passwdEdit->clear();
}
}
void Widget::on_pushButton_clicked()
{
this->close();
}