要求:
1、给窗体改变名称并设置窗口图标、尺寸固定
2、中间放log图
3、用户名和密码使用图片完成
4、账户用明文模式,密码用密文模式
5、点击登录后,将界面上的用户名和“admin”比较,密码和“123456”比较,如果匹配成功,则输出登录成功,如果匹配失败,则输出“账户密码不匹配”,并清空密码框(clear)
6、点击取消后,关闭整个界面
widget:
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
this->setFixedSize(430,330);
this->setWindowIcon(QIcon("D:\\qtt\\day1\\03_first\\QQ.png"));
this->setWindowTitle("QQ");
QLabel *log = new QLabel(this);
log->setPixmap(QPixmap("D:\\qtt\\day1\\zy\\QQbackground.jpeg"));
log->resize(430,130);
// this->setStyleSheet("background-color:rgb(55,97,255)");
QLabel *lab1 = new QLabel("账号:",this);
QLabel *lab2 = new QLabel("密码:",this);
lab1->move(100,180);
lab1->setPixmap(QPixmap("D:\\qtt\\day1\\zy\\qq.png"));
lab1->resize(18,22);
lab1->setScaledContents(true);
lab2->move(100,220);
lab2->setPixmap(QPixmap("D:\\qtt\\day1\\zy\\lock.png"));
lab2->resize(18,22);
lab2->setScaledContents(true);
QLineEdit *edt1 = new QLineEdit("账号",this);
edt1->move(118,180);
edt1->resize(220,25);
QLineEdit *edt2 = new QLineEdit("密码",this);
edt2->move(118,220);
edt2->resize(220,25);
edt2->setEchoMode(QLineEdit::Password);
QPushButton *btn1 = new QPushButton("登录",this);
btn1->move(110,260);
btn1->setStyleSheet("background-color:rgb(8,189,252)");
btn1->resize(100,35);
QPushButton *btn2 = new QPushButton("取消",this);
btn2->setStyleSheet("background-coloc:white");
btn2->resize(100,35);
btn2->move(240,260);
connect(btn1,&QPushButton::clicked,this,[=](){
if(edt1->text()=="admin"&&edt2->text()=="123456")
{
qDebug()<<"登录成功";
}
else
{
qDebug()<<"账号密码不匹配";
edt2->clear();
}
});
connect(btn2,&QPushButton::clicked,this,&Widget::quit);
}
Widget::~Widget()
{
delete ui;
}
void Widget::quit()
{
this->close();
}
head
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QDebug> //包含信息调试类头文件
#include <QIcon> //包含图标的头文件
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QtTextToSpeech>
#include <cstring>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
class Widget : public QWidget
{
Q_OBJECT
signals:
//void mysignal();
public slots:
void quit();
// void myslot();
public:
Widget(QWidget *parent = nullptr);
~Widget();
private:
Ui::Widget *ui;
QLineEdit *edt1;
};
#endif // WIDGET_H