将登录框的两个按钮进行实现,登录按钮需要手动连接自定义的槽函数,取消按钮右键转到槽
对于登录按钮对应的槽函数中实现:判断输入的账号是否等于"admin",密码是否为“123456”,如果匹配成功,则输出登录成功后关闭界面
如果匹配失败,输出账号和密码不匹配,请重新输入,并将密码框内容清空
对于取消按钮,在对应的槽函数中,关闭整个界面即可
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
this->setFixedSize(600,400);
this->setWindowIcon(QIcon("E:\\Qt\\001\\icon\\QQ.png"));
this->setWindowTitle("myQQ");
//this->setStyleSheet("background-color:white;");
btn1=new QPushButton;
btn1->setParent(this);
btn1->setText("登录");
btn1->move(300,330);
btn1->resize(120,40);
btn1->setIcon(QIcon(":/icon/denglu.png"));
connect(btn1,SIGNAL(clicked()),this,SLOT(my_denglu()));
btn1->setStyleSheet("QPushButton{background-color:rgb(7,188,252);border:1px solid white;border-radius:5px;"
"color:white;font:bold 18px};");
btn2=new QPushButton;
btn2->setParent(this);
btn2->setText("取消");
btn2->move(450,330);
btn2->resize(120,40);
btn2->setIcon(QIcon(":/icon/quxiao.png"));
connect(btn2,SIGNAL(clicked()),this,SLOT(my_quxiao()));
btn2->setStyleSheet("QPushButton{background-color:rgb(7,188,252);border:1px solid white;border-radius:5px;"
"color:white;font:bold 18px};");
lab1=new QLabel("账号",this);
lab1->resize(30,30);
lab1->move(120,205);
lab1->setScaledContents(true);
lab1->setPixmap(QPixmap("E:\\Qt\\001\\icon\\zhanghao.png"));
lab2=new QLabel("密码",this);
lab2->resize(30,30);
lab2->move(120,255);
lab2->setScaledContents(true);
lab2->setPixmap(QPixmap("E:\\Qt\\001\\icon\\denglumima.png"));
lab3=new QLabel(this);
lab3->resize(450,350);
lab3->move(80,-60);
lab3->setScaledContents(true);
lab3->setPixmap(QPixmap("E:\\Qt\\001\\icon\\logo.png"));
edit1=new QLineEdit(this);
edit1->resize(300,40);
edit1->move(170,200);
edit1->setPlaceholderText("账号");
edit1->setStyleSheet("QLineEdit{border-top:1px solid white;border-left:1px solid white;border-right:1px solid white;border-radius:5px;"
"font:bold 20px;}");
edit2=new QLineEdit(this);
edit2->resize(300,40);
edit2->move(170,250);
edit2->setPlaceholderText("密码");
edit2->setEchoMode(QLineEdit::Password);
edit2->setStyleSheet("QLineEdit{border-top:1px solid white;border-left:1px solid white;border-right:1px solid white;border-radius:5px;"
"font:bold 20px;}");
}
Widget::~Widget()
{
delete ui;
}
void Widget::my_denglu()
{
if(edit1->text()=="admin"&&edit2->text()=="123456")
{
qDebug()<<"登录成功";
close();
}
else
{
qDebug()<<"登录失败,请重新输入";
edit2->setText("");
}
}
void Widget::my_quxiao()
{
close();
}