qt作业2

cpp 复制代码
#ifndef FAILURE_H
#define FAILURE_H

#include <QWidget>
#include <QTimer>
namespace Ui {
class failure;
}

class failure : public QWidget
{
    Q_OBJECT

public:
    explicit failure(QWidget *parent = nullptr);
    ~failure();
public slots:
void failure_slot();
private:
    Ui::failure *ui;
};

#endif // FAILURE_H
cpp 复制代码
#ifndef SUCCESS_H
#define SUCCESS_H

#include <QWidget>

namespace Ui {
class Success;
}

class Success : public QWidget
{
    Q_OBJECT

public:
    explicit Success(QWidget *parent = nullptr);
    ~Success();
signals:
void my_return();
public slots:
void Login_success();
private slots:
void on_pushButton_clicked();

private:
    Ui::Success *ui;
};

#endif // SUCCESS_H
cpp 复制代码
#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QTimer>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
signals:
void my_login();
void my_failure();
public slots:
void return_slot();
private slots:
void on_pushButton_clicked();

void on_pushButton_2_clicked();

private:
    Ui::Widget *ui;
};
#endif // WIDGET_H
cpp 复制代码
#include "failure.h"
#include "ui_failure.h"

failure::failure(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::failure)
{
    ui->setupUi(this);
    //去掉头部
    this->setWindowFlag(Qt::FramelessWindowHint);
    //去掉组件空白部分
    this->setAttribute(Qt::WA_TranslucentBackground);
}

failure::~failure()
{
    delete ui;
}

void failure::failure_slot()
{
    this->show();
    QTimer::singleShot(600,this,[this]()
    {
        this->close();
    });
}
cpp 复制代码
#include "widget.h"

#include <QApplication>
#include "success.h"
#include "failure.h"
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();
    Success s;
    failure f;
    QObject::connect(&w,&Widget::my_login,&s,&Success::Login_success);
    QObject::connect(&s,&Success::my_return,&w,&Widget::return_slot);
    QObject::connect(&w,&Widget::my_failure,&f,&failure::failure_slot);
    return a.exec();
}
cpp 复制代码
#include "success.h"
#include "ui_success.h"

Success::Success(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Success)
{
    ui->setupUi(this);
    //去掉头部
    this->setWindowFlag(Qt::FramelessWindowHint);
}

Success::~Success()
{
    delete ui;
}

void Success::Login_success()
{
    this->show();
}

void Success::on_pushButton_clicked()
{
    emit my_return();
    this->close();
}
cpp 复制代码
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //去掉头部
    this->setWindowFlag(Qt::FramelessWindowHint);
    //去掉组件空白部分
    this->setAttribute(Qt::WA_TranslucentBackground);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::return_slot()
{
    this->show();
}


void Widget::on_pushButton_clicked()
{
    if(ui->lineEdit->text()=="admin"&&ui->lineEdit_2->text()=="123456")
    {
    emit my_login();
    this->close();
    }
    else
    {

        ui->lineEdit_2->setText("");
            emit my_failure();

    }
}

void Widget::on_pushButton_2_clicked()
{
    ui->lineEdit->setText("");
    ui->lineEdit_2->setText("");
}
cpp 复制代码
*{
	background-color: rgb(255, 255, 255);
	border-radius:30px;
}
QFrame#frame{
	
	background-color: qconicalgradient(cx:0.5, cy:0.5, angle:0, stop:0 rgba(0, 255, 255, 255), stop:0.373979 rgba(255, 255, 255, 255), stop:0.373991 rgba(33, 30, 255, 255), stop:0.624018 rgba(33, 30, 255, 255), stop:0.624043 rgba(255, 0, 0, 255), stop:1 rgba(255, 0, 0, 255));
	border-image: url(:/Logo/shangHai.jpg);
	border-radius:30px;
	
}
#frame_2{
	
	background-color: rgba(130, 130, 130, 100);
	border-radius:30px;
}

QLabel#label{
	background-color: rgba(154, 154, 154, 100);
	border-radius:30px;
}
QLabel#label_2{
	font: 20pt "楷体";
	border-radius:30px;
	background-color: rgba(255, 255, 255, 0);
	color: rgba(255, 255, 255, 150);
}
QLineEdit#lineEdit
{
	background:transparent;
	border:none;
	border-bottom:1px solid rgba(255,255,255,150);
	color: rgba(255, 255, 255, 150);
}
QLineEdit#lineEdit_2
{
	background:transparent;
	border:none;
	border-bottom:1px solid rgba(255,255,255,150);
	color: rgba(255, 255, 255, 150);
}
QLineEdit#lineEdit_3
{
	background:transparent;
	border:none;
	border-bottom:1px solid rgba(255,255,255,150);
}
QPushButton#pushButton
{
	border-radius:10px;
	color: rgba(255, 255, 255, 150);
	
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(0, 145, 171, 255), stop:1 rgba(255, 255, 255, 255));
}
QPushButton#pushButton:hover
{
	border-radius:10px;
	color: rgba(255, 255, 255, 150);
	
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(0, 185, 171, 255), stop:1 rgba(255, 255, 255, 255));
}
QPushButton#pushButton:pressed
{
	border-radius:10px;
	color: rgba(255, 255, 255, 150);
	
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(0, 145, 171, 255), stop:1 rgba(255, 255, 255, 255));
	padding-top:5px;
}
QPushButton#pushButton_2
{
	border-radius:10px;
	color: rgba(255, 255, 255, 150);
	
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(0, 145, 171, 255), stop:1 rgba(255, 255, 255, 255));
}
QPushButton#pushButton_2:hover
{
	border-radius:10px;
	color: rgba(255, 255, 255, 150);
	
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(0, 185, 171, 255), stop:1 rgba(255, 255, 255, 255));
}
QPushButton#pushButton_2:pressed
{
	border-radius:10px;
	color: rgba(255, 255, 255, 150);
	
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(0, 145, 171, 255), stop:1 rgba(255, 255, 255, 255));
	padding-top:5px;
}
QPushButton#pushButton_3
{
	border-radius:10px;
	color: rgba(255, 255, 255, 150);
	
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(0, 145, 171, 255), stop:1 rgba(255, 255, 255, 255));
}
QPushButton#pushButton_3:hover
{
	border-radius:10px;
	color: rgba(255, 255, 255, 150);
	
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(0, 185, 171, 255), stop:1 rgba(255, 255, 255, 255));
    
}

输入账号密码,账号密码正确,登录成功

关掉本界面,弹出下一个界面,点击返回回到刚才的界面

如果账号密码错误,则弹出登录失败,6秒后消失

相关推荐
侃侃_天下2 天前
最终的信号类
开发语言·c++·算法
echoarts2 天前
Rayon Rust中的数据并行库入门教程
开发语言·其他·算法·rust
Aomnitrix2 天前
知识管理新范式——cpolar+Wiki.js打造企业级分布式知识库
开发语言·javascript·分布式
每天回答3个问题2 天前
UE5C++编译遇到MSB3073
开发语言·c++·ue5
伍哥的传说2 天前
Vite Plugin PWA – 零配置构建现代渐进式Web应用
开发语言·前端·javascript·web app·pwa·service worker·workbox
小莞尔2 天前
【51单片机】【protues仿真】 基于51单片机八路抢答器系统
c语言·开发语言·单片机·嵌入式硬件·51单片机
我是菜鸟0713号2 天前
Qt 中 OPC UA 通讯实战
开发语言·qt
JCBP_2 天前
QT(4)
开发语言·汇编·c++·qt·算法
Brookty2 天前
【JavaEE】线程安全-内存可见性、指令全排序
java·开发语言·后端·java-ee·线程安全·内存可见性·指令重排序
百锦再2 天前
[特殊字符] Python在CentOS系统执行深度指南
开发语言·python·plotly·django·centos·virtualenv·pygame