second.h文件:
#ifndef SECOND_H
#define SECOND_H#include <QWidget>
#include <QWidget>
#include <QDebug>
#include <QIcon>
#include <QButtonGroup>
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>
#include <QTextEdit>
#include <QMessageBox>
#include <QApplication>namespace Ui {
class second;
}class second : public QWidget
{Q_OBJECTpublic:explicit second(QWidget *parent = nullptr);~second();public slots://定义有关处理跳转信号的槽函数void jump_slot();private:Ui::second *ui;QLabel *lab1;
};#endif // SECOND_H
second.cpp
#include "second.h"
#include "ui_second.h"second::second(QWidget *parent) :QWidget(parent),ui(new Ui::second)
{ui->setupUi(this);qDebug()<<this->size();qDebug()<<this->frameSize();this->setFixedSize(1280,720);//设置标题this->setWindowTitle("League of Legends");qDebug()<<this->windowTitle();//设置窗口图标this->setWindowIcon(QIcon(":/prefix/game.png"));//设置logolab1 = new QLabel(this);lab1->setStyleSheet("background-color:#FFEBCD;");lab1->resize(1280,720);lab1->setPixmap(QPixmap(":/prefix/001.jpg"));//自适应lab1->setScaledContents(true);
}second::~second()
{delete ui;
}void second::jump_slot()
{this->show();
}
widget.h
#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <QWidget>
#include <QDebug>
#include <QIcon>
#include <QButtonGroup>
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>
#include <QTextEdit>
#include <QMessageBox>
#include <QApplication>namespace Ui {
class Widget;
}class Widget : public QWidget
{Q_OBJECTsignals:void my_signal();void jump_second();public:explicit Widget(QWidget *parent = nullptr);~Widget();private slots:void on_closeBtn_clicked();void login_clicked();void on_btn0_clicked();void on_jumpBtn_clicked();private:Ui::Widget *ui;QLineEdit *edit1;QLineEdit *edit2;QPushButton *btn2;QPushButton *btn1;QPushButton *btn0;QLabel *lab1;QPushButton *btn4;
};#endif // WIDGET_H
widget.cpp
#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent) :QWidget(parent),ui(new Ui::Widget)
{ui->setupUi(this);qDebug()<<this->size();qDebug()<<this->frameSize();this->setFixedSize(500,700);//设置标题this->setWindowTitle("League of Legends启动器");qDebug()<<this->windowTitle();//设置窗口图标this->setWindowIcon(QIcon(":/prefix/game.png"));//更改背景颜色this->setStyleSheet("background-color:#FFEBCD;");//设置窗口透明度//this->setWindowOpacity(0.9);/*********************************************///设置logolab1 = new QLabel(this);lab1->setStyleSheet("background-color:#FFEBCD;");lab1->resize(500,300);lab1->setPixmap(QPixmap(":/prefix/log.svg"));//自适应lab1->setScaledContents(true);//账户图标QLabel *lab2 = new QLabel(this);lab2->resize(50,50);lab2->setPixmap(QPixmap(":/prefix/login.svg"));lab2->move(100,330);//自适应lab2->setScaledContents(true);//密码图标QLabel *lab3 = new QLabel(this);lab3->resize(50,50);lab3->setPixmap(QPixmap(":/prefix/passwd.svg"));lab3->move(100,430);//自适应lab3->setScaledContents(true);/*********************************************//*********************************************///设置行输入//账号edit1 = new QLineEdit(this);edit1->resize(240,50);edit1->move(200,330);edit1->setStyleSheet("border:none;");edit1->setPlaceholderText("QQ号/手机号/邮箱");//设置字体大小edit1->setFont(QFont("宋体",15));//密码edit2 = new QLineEdit(this);edit2->resize(edit1->size());edit2->move(200,430);//获取 文本框内容qDebug()<<edit2->text();//将文本内容设置密文模式edit2->setEchoMode(QLineEdit::Password);edit2->setPlaceholderText("密码");//设置字体大小edit2->setFont(QFont("宋体",15));edit2->setStyleSheet("border:none;");/*********************************************//*********************************************///按键//登录btn1 = new QPushButton(QIcon(":/prefix/login_button.svg"),"登录",this);btn1->resize(100,50);btn1->move(200,530);btn1->setFont(QFont("宋体",15));//登出btn2 = new QPushButton(QIcon(":/prefix/no.svg"),"取消",this);btn2->resize(100,50);btn2->move(200,600);btn2->setFont(QFont("宋体",15));//清除btn0 = new QPushButton("清除",this);btn0->resize(100,50);btn0->move(400,650);btn0->setFont(QFont("宋体",15));connect(btn2,&QPushButton::clicked,[=](){this->close();});connect(btn1,SIGNAL(clicked()),this,SLOT(login_clicked()));connect(btn0,SIGNAL(clicked()),this,SLOT(on_btn0_clicked()));//手动链接my_signal信号对应的槽函数connect(this,&Widget::my_signal,[&](){edit1->clear();edit2->clear();});}void Widget::on_closeBtn_clicked()
{
}void Widget::login_clicked()
{if(edit1->text()=="admin" && edit2->text()=="123456"){qDebug()<<"登陆成功";emit jump_second();this->hide();}else {qDebug()<<"登录失败";}
}void Widget::on_btn0_clicked()
{emit my_signal();
}void Widget::on_jumpBtn_clicked()
{emit jump_second();//隐藏this->hide();
}Widget::~Widget()
{delete ui;
}
main.cpp
#include "widget.h"
#include "second.h"
#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);Widget w;w.show();second s;//将第一个界面的信号与第二个界面的槽进行链接QObject::connect(&w,&Widget::jump_second,&s,&second::jump_slot);return a.exec();
}
结果: