widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QPushButton>
#include <QDebug>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
private slots:
void on_cancer_clicked();
private:
Ui::Widget *ui;
//自定义槽体
void my_soltlogin();
};
#endif // WIDGET_H
2.widget.cpp
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
//设置窗体的尺寸
this->resize(800,600);
this->setFixedSize(this->size());
//设置窗口标题
this->setWindowTitle("JackNB的杂货铺");
//设置窗口图标
this->setWindowIcon(QIcon("D:/C++&QT/icon/2.png"));
//设置背景logo的大小
this->ui->backlabel->setGeometry(0,0,800,260); //设置logo空件的坐标和大小
ui->backlabel->setPixmap(QPixmap("D:/C++&QT/icon/1.png"));
ui->backlabel->setScaledContents(true); //自适应图片大小
//设置usrname,pwd的大小和图标
ui->userlabel->resize(35,35);
ui->userlabel->setScaledContents(true);
ui->userlabel->setPixmap(QPixmap("D:/C++&QT/icon/userName.jpg"));
ui->pwdlabel->resize(35,35);
ui->pwdlabel->setScaledContents(true);
ui->pwdlabel->setPixmap(QPixmap("D:/C++&QT/icon/passwd.jpg"));
//设置输入框的属性
ui->userline->resize(270,35);
ui->userline->setPlaceholderText("账号/邮箱/手机号");
ui->pwdline->resize(270,35);
ui->pwdline->setPlaceholderText("密码");
ui->pwdline->setEchoMode(QLineEdit::Password); //密文模式
//设置登录和取消按钮的大小和图片
ui->login->resize(150,50);
ui->login->setText("登录");
ui->cancer->resize(150,50);
ui->cancer->setText("取消");
//定义连接槽函数
connect(ui->login,&QPushButton::clicked,this,&Widget::my_soltlogin);
}
Widget::~Widget()
{
delete ui;
}
void Widget::my_soltlogin()
{
QString username=ui->userline->text();
QString pwd=ui->pwdline->text();
if("admin" == username && "123456"==pwd )
{
qDebug()<<"登录成功";
this->close();
}
else
{
qDebug()<<"登录失败";
ui->pwdline->clear();
}
}
void Widget::on_cancer_clicked()
{
close();
}