qt作业2
#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
#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
#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
#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();
});
}
#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();
}
#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();
}
#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("");
}
*{
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秒后消失
原文地址:https://blog.csdn.net/affkjafhakjhf/article/details/144793977
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!