练习:优化登录框,输入完用户名和密码后,点击登录,判断账户是否为 Admin 密码 为123456,如果判断成功,则输出登录成功,并关闭整个登录界面,如果登录失败,则提示登录失败,并将账号和密码的行编辑器中的内容清空
#include "mywidget.h"MyWidget::MyWidget(QWidget *parent): QWidget(parent)
{//设置标题this->setWindowTitle("登录");//设置图标this->setWindowIcon(QIcon(":/new/prefix1/C:/Users/DC/Desktop/pictrue/qq.png"));//设置背景颜色this->setStyleSheet("background-color:rgb(255,255,255)");//固定窗口大小this->setFixedSize(540,400);//去掉头部//this->setWindowFlag(Qt::FramelessWindowHint);QLabel *lab1=new QLabel("标签",this);lab1->resize(540,400);lab1->setStyleSheet("background-color:green");QMovie *mv = new QMovie(":/new/prefix1/C:/Users/DC/Desktop/pictrue/zz.gif");//将动图放入标签中lab1->setMovie(mv);//让动图动起来mv->start();//自动适应lab1->setScaledContents(true);QLabel *lab2=new QLabel("账号",this);lab2->resize(40,40);lab2->setPixmap(QPixmap(":/new/prefix1/C:/Users/DC/Desktop/pictrue/1.png"));lab2->move(100,100);lab2->setScaledContents(true);QLabel *lab3=new QLabel("密码",this);lab3->resize(40,40);lab3->setPixmap(QPixmap(":/new/prefix1/C:/Users/DC/Desktop/pictrue/2.jpg"));lab3->move(100,150);lab3->setScaledContents(true);edit1=new QLineEdit;edit1->setPlaceholderText("QQ号/手机号");edit1->setParent(this);edit1->resize(260,40);edit1->move(150,100);edit2=new QLineEdit("密码",this);edit2->setEchoMode(QLineEdit::Password);edit2->resize(260,40);edit2->move(150,150);btn1=new QPushButton("登录",this);btn1->resize(120,50);btn1->move(210,200);//btn1->setEnabled(false);//样式函数setStyleSheet()btn1->setStyleSheet("background-color:rgb(8,189,253);border-radius:5px;color:white");connect(this->btn1,&QPushButton::clicked,this,&MyWidget::myslots);
}MyWidget::~MyWidget()
{
}
void MyWidget::myslots(void)
{if(this->edit1->text()=="root"&&this->edit2->text()=="123"){qDebug()<<"登录成功";this->close();}else{qDebug()<<"登录失败";this->edit1->clear();this->edit2->clear();}
}