头文件?
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QIcon>
#include <QLabel>
#include <QLineEdit>
#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();
public slots:
void btn1_slot();
private:
Ui::Widget *ui;
};
#endif // WIDGET_H
函数
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
//设置窗口
this->setWindowTitle("GTA5");
this->setWindowIcon(QIcon(":/pictrue/gta.jfif"));
this->setWindowFlags(Qt::FramelessWindowHint);
//设置标签
//整个背景
ui->lab1->setPixmap(QPixmap(":/pictrue/gta_login.jpg"));
ui->lab1->setScaledContents(true);
//R星logo
ui->lab2->setPixmap(QPixmap(":/pictrue/rxing.png"));
ui->lab2->setScaledContents(true);
ui->lab2->setStyleSheet("border-radius:10px");
ui->lab3->setPixmap(QPixmap(":/pictrue/denglu.webp"));
ui->lab4->setPixmap(QPixmap(":/pictrue/passwd.jpg"));
ui->lab3->setScaledContents(true);
ui->lab4->setScaledContents(true);
//设置行编辑器
ui->edit1->setPlaceholderText("账号/邮箱");
ui->edit2->setPlaceholderText("密码");
ui->edit2->setEchoMode(QLineEdit::Password);
//QT4手动关闭槽函数
connect(ui->btn2,SIGNAL(clicked()),this,SLOT(close()));
connect(ui->btn1,&QPushButton::clicked,this,&Widget::btn1_slot);
}
Widget::~Widget()
{
delete ui;
}
void Widget::btn1_slot()
{
if(ui->edit1->text()=="admin"&&ui->edit2->text()=="123456")
{
qDebug()<<"登录成功";
this->close();
}
else
{
qDebug()<<"登录失败";
ui->edit2->setText("");
}
}
效果图
?