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

相关推荐
用户805533698033 天前
不止三件套:QObject 属性系统全关键字与运行时反射!
c++·qt
xcyxiner3 天前
DicomViewer (vcpkg Windows和ubuntu编译)7
qt
Quz8 天前
QML Hello World 入门示例
qt
xcyxiner11 天前
DicomViewer (dcmtk读取dcm文件)5
qt
xcyxiner11 天前
DicomViewer (后台线程处理文件)4
qt
xcyxiner12 天前
DicomViewer (添加模型类)3
qt
xcyxiner12 天前
DicomViewer (目录调整) 2
qt
xcyxiner13 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
LDR00614 天前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
雪碧聊技术14 天前
Tree.js是什么?一文讲透
开发语言·javascript·ecmascript