第一个页面头文件
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include<QPushButton>
#include<QDebug>
#include<QtDebug>
#include<iostream>
#include<QIcon>
#include<QPushButton>
#include<QLineEdit>
#include<QLabel>
#include<QMessageBox>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void on_login_clicked();
void on_cancel_clicked();
signals:
void jump();
private:
Ui::MainWindow *ui;
QLineEdit *account;
QLineEdit *login;
};
#endif // MAINWINDOW_H
第一个页面源代码
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
this->setFixedSize(400,360);
ui->setupUi(this);
this->setWindowIcon(QIcon(":/new/prefix1/icon/1.png"));
// this->setStyleSheet("background-color:rgb(222,222,222)");
this->setWindowTitle("combat simulator");
QPushButton *login = new QPushButton("login",this);
login->resize(80,30);
login->move(120,280);
login->setIcon(QIcon(":/new/prefix1/icon/2.png"));
connect(login,SIGNAL(clicked()),this,SLOT(on_login_clicked()));
QPushButton *cancel = new QPushButton("cancel",this);
cancel->resize(login->size());
cancel->move(login->x()+130,login->y());
cancel->setIcon(QIcon(":/new/prefix1/icon/cancel.png"));
connect(cancel,SIGNAL(clicked()),this,SLOT(on_cancel_clicked()));
QLineEdit *account= new QLineEdit(this);
account->resize(200,30);
account->move(login->x(), login->y()-120);
account->setPlaceholderText("please enter your account");
QLineEdit *password= new QLineEdit(this);
password->resize(200,30);
password->move(login->x(), login->y()-70);
password->setPlaceholderText("please enter your password");
QLabel *title = new QLabel(this);
title->resize(400,150);
title->setPixmap(QPixmap(":/new/prefix2/title/title3.png"));
QLabel *accounticon = new QLabel(this);
accounticon->resize(30,30);
accounticon->move(account->x()-40,account->y());
accounticon->setPixmap(QPixmap(":/new/prefix1/icon/lock.png"));
accounticon->setScaledContents(true);
accounticon->setScaledContents(true);
QLabel *passwordicon = new QLabel(this);
passwordicon->resize(30,30);
passwordicon->move(password->x()-40,password->y());
passwordicon->setPixmap(QPixmap(":/new/prefix1/icon/lock glitch.png"));
passwordicon->setScaledContents(true);
passwordicon->setScaledContents(true);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_login_clicked(){
if(account->text() =="admin"&&login->text()=="123456"){
QMessageBox::information(this,"提示","登录成功",QMessageBox::Yes);
this->close();
emit jump();
}
else{
QMessageBox::warning(this,"警告","账户或密码错误",
QMessageBox::Yes,QMessageBox::Yes);
}
}
void MainWindow::on_cancel_clicked(){
QMessageBox box(QMessageBox::Question,
"提示",
"是否退出?",
QMessageBox::Yes|QMessageBox::No,
this);
int ret= box.exec();
if(ret == QMessageBox::Yes){
close();
}
else if(ret == QMessageBox::No){
}
}
第二个页面头文件
#ifndef MEAN_H
#define MEAN_H
#include <QWidget>
namespace Ui {
class mean;
}
class mean : public QWidget
{
Q_OBJECT
public:
explicit mean(QWidget *parent = nullptr);
~mean();
public slots:
void jump_slot();
private:
Ui::mean *ui;
};
#endif // MEAN_H
第二个页面源代码
#include "mean.h"
#include "ui_mean.h"
mean::mean(QWidget *parent) :
QWidget(parent),
ui(new Ui::mean)
{
ui->setupUi(this);
}
mean::~mean()
{
delete ui;
}
void mean::jump_slot()
{
this->show();
}
主函数代码
#include "mainwindow.h"
#include "mean.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}