华清远见第六课程作业day9

第一个页面头文件

#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();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值