C++ day3

widget样式表

*{
	
	background-color: rgb(255, 255, 255);
}
QFrame#frame{
	border-radius:25px;
	border-image: url(:/Logo/shanChuan.jpg);
}

#frame_2{
	border-radius:25px;
	background-color: rgba(154, 154, 154, 120);
}
QLabel#label{
	border-radius:25px;
	background-color: rgba(103, 103, 103, 120);
}
#label_2{
	background:transparent;
	color: white;
	font: 75 15pt "Times New Roman";
	
	color: rgba(255, 255, 255, 140);
}
QLineEdit{
	background:transparent;
	border:none;
	border-bottom:1px solid rgba(255, 255, 255, 120);
	
	color: rgba(255, 255, 255, 120);
	
	font: 9pt "Times New Roman";
}
QPushButton#pushButton{
	
	color: rgba(255, 255, 255, 120);
	
	font: 14pt "Times New Roman";
	
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(46, 122, 214, 255), stop:1 rgba(255, 255, 255, 255));
	border-radius:5px;
}

QPushButton:hover#pushButton{
	
	color: rgba(255, 255, 255, 120);
	
	font: 14pt "Times New Roman";
	
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(80, 122, 214, 255), stop:1 rgba(255, 255, 255, 255));
	border-radius:5px;
}

QPushButton:pressed#pushButton{
	
	color: rgba(255, 255, 255, 120);
	
	font: 14pt "Times New Roman";
	
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(46, 122, 214, 255), stop:1 rgba(255, 255, 255, 255));
	border-radius:5px;
	padding-top:5px;
	padding-left:5px;
}
QPushButton#closeButton{
	background-color: transparent;
    border: none;
	font: 75 16pt "等线";
	border-radius:5px;
}
QPushButton:hover#closeButton{
	background-color: transparent;
    border: none;
	font: 75 16pt "等线";
	background-color: rgba(255, 0, 0, 80);
	border-radius:5px;
}
QPushButton:pressed#closeButton{
	background-color: transparent;
    border: none;
	font: 75 16pt "等线";
	border-radius:5px;
	padding-top:5px;
    padding-left:5px;
}
QPushButton#shrinkButton{
	background-color: transparent;
    border: none;
	border-radius:5px;
	font: 75 30pt "等线";
}
QPushButton:hover#shrinkButton{
	background-color: transparent;
    border: none;
	border-radius:5px;
	background-color: rgba(255, 238, 244, 80);
	font: 75 30pt "等线";
}
QPushButton:pressed#shrinkButton{
	background-color: transparent;
    border: none;
	font: 75 30pt "等线";
	border-radius:5px;
	padding-top:5px;
    padding-left:5px;
}

widget.h

#ifndef WIDGET_H
#define WIDGET_H

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

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

private slots:
    void on_pushButton_clicked();
    void on_closeButton_clicked();

    void on_shrinkButton_clicked();

signals:
    void jumpToSecondWindow();
private:
    Ui::Widget *ui;
};
#endif // WIDGET_H

widget.cpp

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    setWindowFlag(Qt::FramelessWindowHint);

    // 去掉空白
    setAttribute(Qt::WA_TranslucentBackground);
}

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


void Widget::on_pushButton_clicked()
{
    if(ui->actLineEdit->text() == "admin" && ui->pwdLineEdit->text() == "123456")
    {
        close();
        emit jumpToSecondWindow();
    }
    else
    {
        QMessageBox::critical(this, "Login Error", "账号或密码错误!");
        // 清空账号和密码输入行
        ui->actLineEdit->clear();
        ui->pwdLineEdit->clear();
    }
}

void Widget::on_closeButton_clicked()
{
    close();
}

void Widget::on_shrinkButton_clicked()
{
    showMinimized();
}

Second.h

#ifndef SECOND_H
#define SECOND_H

#include <QWidget>

namespace Ui {
class Second;
}

class Second : public QWidget
{
    Q_OBJECT

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

#endif // SECOND_H

Second.cpp

#include "second.h"
#include "ui_second.h"

Second::Second(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Second)
{
    ui->setupUi(this);
}

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

void Second::mySlot()
{
   show();
}
相关推荐
蜀黍@猿17 分钟前
【C++ 基础】从C到C++有哪些变化
c++
Am心若依旧40918 分钟前
[c++11(二)]Lambda表达式和Function包装器及bind函数
开发语言·c++
明月看潮生20 分钟前
青少年编程与数学 02-004 Go语言Web编程 20课题、单元测试
开发语言·青少年编程·单元测试·编程与数学·goweb
zh路西法28 分钟前
【C++决策和状态管理】从状态模式,有限状态机,行为树到决策树(一):从电梯出发的状态模式State Pattern
c++·决策树·状态模式
大G哥30 分钟前
java提高正则处理效率
java·开发语言
VBA633740 分钟前
VBA技术资料MF243:利用第三方软件复制PDF数据到EXCEL
开发语言
轩辰~42 分钟前
网络协议入门
linux·服务器·开发语言·网络·arm开发·c++·网络协议
小_太_阳1 小时前
Scala_【1】概述
开发语言·后端·scala·intellij-idea
向宇it1 小时前
【从零开始入门unity游戏开发之——unity篇02】unity6基础入门——软件下载安装、Unity Hub配置、安装unity编辑器、许可证管理
开发语言·unity·c#·编辑器·游戏引擎
lxyzcm1 小时前
C++23新特性解析:[[assume]]属性
java·c++·spring boot·c++23