widget.cpp
#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);//设置窗口标题this->setWindowTitle("QQ");//设置窗口图标this->setWindowIcon(QIcon(":/pictrue/QQ123.png"));QMovie *mv=new QMovie(":/pictrue/plane.gif"); //创建一个动图ui->label->setMovie(mv); //将动图插入标签mv->start(); //启动动图ui->label->setScaledContents(true); //让动图自适应标签大小ui->userLabel->setPixmap(QPixmap(":/pictrue/user.png")); //设置标签显示图片ui->userLabel->setScaledContents(true); //让图片自适应标签大小ui->passwdLabel->setPixmap(QPixmap(":/pictrue/passwd.jpg"));//设置标签显示图片ui->passwdLabel->setScaledContents(true); //让图片自适应标签大小ui->passwdEdit->setEchoMode(QLineEdit::Password); //设置行编辑器显示模式为Password}Widget::~Widget()
{delete ui;
}//登录按钮的槽函数实现
void Widget::on_loginBtn_clicked()
{if(ui->userEdit->text().isEmpty() || ui->passwdEdit->text().isEmpty()){QMessageBox::information(this,"登录","请将登录信息填写完整!");return;}/*账号密码匹配*/if(ui->userEdit->text()=="admin" && ui->passwdEdit->text()=="123456"){QMessageBox::information(this,"登录","登录成功");emit this->loginSuccess_signal(); //触发登录成功信号this->close(); //退出窗口}else/*账号密码不匹配*/{QMessageBox msg(QMessageBox::Critical,"登录","账号和密码不匹配,是否重新登录",QMessageBox::Yes|QMessageBox::No,this );int ret= msg.exec(); //调用exec弹出对话框/*判断用户选中的按钮*/if(ret==QMessageBox::Yes){ui->passwdEdit->setText(""); //将密码文本清空}else if(ret==QMessageBox::No){this->close(); //退出窗口}}}