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秒后消失

相关推荐
C#Thread10 分钟前
C#上位机--流程控制(IF语句)
开发语言·javascript·ecmascript
牵牛老人43 分钟前
Qt开发中出现中文乱码问题深度解析与解决方案
开发语言·qt
大脑经常闹风暴@小猿44 分钟前
1.1 go环境搭建及基本使用
开发语言·后端·golang
奔跑吧邓邓子1 小时前
【Python爬虫(45)】Python爬虫新境界:分布式与大数据框架的融合之旅
开发语言·分布式·爬虫·python·大数据框架
Evaporator Core1 小时前
MATLAB学习之旅:数据建模与仿真应用
开发语言·学习·matlab
Zfox_1 小时前
【QT】信号与槽 & 窗口坐标
开发语言·c++·qt·qt5
张鱼小丸子1 小时前
【无标题】云原生作业六
开发语言·php
项目申报小狂人2 小时前
改进收敛因子和比例权重的灰狼优化算法【期刊论文完美复现】(Matlab代码实现)
开发语言·算法·matlab
JD技术委员会3 小时前
Rust 语法噪音这么多,是否适合复杂项目?
开发语言·人工智能·rust
Hello.Reader3 小时前
Rust 中的 `Drop` 特性:自动化资源清理的魔法
开发语言·rust·自动化