思维导图
实现界面的跳转
widget头文件
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QDebug>
#include <QIcon>
#include <QPushButton>
#include <QLineEdit>
#include <QLabel>
#include <QMovie>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
QLabel *lab1;
QLabel *lab2;
QLabel *lab3;
QPushButton *btn1;
QPushButton *btn2;
QLineEdit *edit1;
QLineEdit *edit2;
QMovie *movie1;
QLabel *lab4;
signals: //该权限下说明要定义信号函数
void my_signal(); //定义自定义的信号函数
void jump();
public slots:
void btn1_slot(); //自定义的槽函数
void btn2_slot(); //自定义的槽函数
};
#endif // WIDGET_H
widget源文件
#include "widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
//设置窗口固定尺寸
this->setFixedSize(480,430);
//窗口标题
this->setWindowTitle("耗子尾汁");
this->setWindowIcon(QIcon(":/my/my_icon.png"));
//设置透明度
this->setWindowOpacity(0.9);
//构造logo标签
movie1 = new QMovie(":/my/111.gif");
lab1 = new QLabel(this);
lab1->resize(480,200);
lab1->move(0,0);
lab1->setMovie(movie1);
movie1->start();
lab1->setScaledContents(true);
//构造用户标签
lab2 = new QLabel(this);
lab2->resize(30,30);
lab2->move(100,250);
lab2->setPixmap(QPixmap(":/my/denglu.png"));
lab2->setScaledContents(true);
//构造密码标签
lab3 = new QLabel(this);
lab3->resize(30,30);
lab3->move(100,300);
lab3->setPixmap(QPixmap(":/my/denglumima.png"));
lab3->setScaledContents(true);
//构造用户名行编辑
edit1 = new QLineEdit(this);
edit1->resize(200,30);
edit1->move(150,250);
edit1->setPlaceholderText("用户名");
edit1->setStyleSheet("border:none;"
"border-bottom: 2px solid skyblue;");
//构造密码行编辑
edit2 = new QLineEdit(this);
edit2->move(150,300);
edit2->resize(edit1->size());
edit2->clear();
edit2->setEchoMode(QLineEdit::Password);
edit2->setPlaceholderText("密码");
edit2->setStyleSheet("border:none;"
"border-bottom: 2px solid skyblue;");
//构造登录按钮
btn1 = new QPushButton(QIcon(":/my/denglu_1.png"),"登录",this);
btn1->resize(80,30);
btn1->move(200,360);
btn1->setStyleSheet("background-color:skyblue; border-radius:10px;");
//构造取消按钮
btn2 = new QPushButton(QIcon(":/my/quxiao.png"),"取消",this);
btn2->resize(80,30);
btn2->move(300,360);
btn2->setStyleSheet("background-color:skyblue; border-radius:10px;");
//取消按钮与槽函数连接取消
connect(btn2,SIGNAL(clicked()),this,SLOT(btn2_slot()));
//登录按钮与槽函数连接
connect(btn1,&QPushButton::clicked,this,&Widget::btn1_slot);
}
Widget::~Widget()
{
}
void Widget::btn1_slot()
{
if(this->edit1->text() == "admin" && this->edit2->text() == "123456")
{
qDebug() << "登录成功";
emit jump();
this->close();
}
else
{
qDebug() << "登录失败";
edit2->clear();
}
}
void Widget::btn2_slot()
{
this->close();
}
form头文件
#ifndef FORM_H
#define FORM_H
#include <QWidget>
#include <QDebug>
#include <QIcon>
#include <QPushButton>
#include <QLineEdit>
#include <QLabel>
#include <QMovie>
namespace Ui {
class Form;
}
class Form : public QWidget
{
Q_OBJECT
public:
explicit Form(QWidget *parent = nullptr);
~Form();
QLabel *lab1;
QLabel *lab2;
QLabel *lab3;
QPushButton *btn1;
QPushButton *btn2;
QLineEdit *edit1;
QLineEdit *edit2;
QMovie *movie1;
public slots:
void jump_slot();
private:
Ui::Form *ui;
};
#endif // FORM_H
form源文件
#include "form.h"
#include "ui_form.h"
Form::Form(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form)
{
ui->setupUi(this);
//设置窗口固定尺寸
this->setFixedSize(480,200);
//窗口标题
this->setWindowTitle("你干嘛");
this->setWindowIcon(QIcon(":/my/my_icon.png"));
//设置透明度
this->setWindowOpacity(0.9);
//构造logo标签
movie1 = new QMovie(":/my/111.gif");
lab1 = new QLabel(this);
lab1->resize(480,200);
lab1->move(0,0);
lab1->setMovie(movie1);
movie1->start();
lab1->setScaledContents(true);
}
Form::~Form()
{
delete ui;
}
void Form::jump_slot()
{
this->show();
}
main
#include "widget.h"
#include "form.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
Form f;
QObject::connect(&w,&Widget::jump,&f,&Form::jump_slot);
return a.exec();
}