#include "widget.h"
#include "ui_widget.h"
#include <QTimer>
using namespace std;
Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget), lab1(new QLabel(this)) //初始化一个标签显示登录状态
{//设置华清远见的标签图片this->setFixedSize(440,442);ui->setupUi(this);ui->Log->setPixmap(QPixmap(":/pictrue/logo.png"));ui->Log->setScaledContents(true);//设置账号前面的图标ui->User->setPixmap(QPixmap(":/pictrue/qq.png"));ui->User->setScaledContents(true);//设置密码前面的图标ui->Passed->setPixmap(QPixmap(":/pictrue/suo.png"));ui->Passed->setScaledContents(true);//密码设置成密码模式ui->PassedLine->setEchoMode(QLineEdit::Password);//创建一个关闭按钮QPushButton *btn3 = new QPushButton("关闭",this);btn3->resize(ui->QuXiao->size().width(),ui->QuXiao->size().height());btn3->move(ui->QuXiao->x(),ui->BianSe->y());
// connect(btn3,SIGNAL(clicked()),this,SLOT(my_slot()));//登录后进行判断账号密码是否正确connect(ui->DengLu,SIGNAL(clicked()),this,SLOT(my_slot()));
}Widget::~Widget()
{delete ui;
}
//槽函数
void Widget::my_slot()
{//判断账号密码是否正确QString s1(ui->UserLine->text());QString s2(ui->PassedLine->text());//设置登录状态的标签的格式lab1->resize(ui->QuXiao->size().width(),ui->QuXiao->size().height());lab1->move(ui->PassedLine->x()+10,ui->PassedLine->y()+30);lab1->setStyleSheet("background-color:rgb(240,240,240);color:black");if((s1 == "admin") & (s2 == "123456")){//判断正确lab1->setText("登录成功");//延时后退出界面QTimer::singleShot(3000,[&](){this->close();});}else{//登录失败lab1->setText("登录失败");//失败后清除ui->UserLine->clear();ui->PassedLine->clear();}
}
//变色按钮功能
void Widget::on_BianSe_clicked()
{static int count = 0;if(++count % 4 == 1){this->setStyleSheet("background-color:red");}else if(count % 4 == 2){this->setStyleSheet("background-color:green");}else if(count % 4 == 3){this->setStyleSheet("background-color:blue");}else if(count % 4 == 0){this->setStyleSheet("background-color:rgb(255,255,255)");}
}
//取消关闭函数
void Widget::on_QuXiao_clicked()
{this->close();
}
作业