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();
}
相关推荐
褚翾澜2 分钟前
Haskell语言的NoSQL
开发语言·后端·golang
小王努力学编程11 分钟前
【Linux系统编程】进程概念,进程状态
linux·运维·服务器·c++
zh_xuan14 分钟前
LeeCode 57. 插入区间
c语言·开发语言·数据结构·算法
2401_8534482319 分钟前
C嘎嘎类里面的额函数
c语言·开发语言·c++
莫有杯子的龙潭峡谷21 分钟前
4.4 代码随想录第三十五天打卡
c++·算法
luckyme_27 分钟前
leetcode 代码随想录 数组-区间和
c++·算法·leetcode
巷北夜未央29 分钟前
数据结构之二叉树Python版
开发语言·数据结构·python
wen__xvn1 小时前
每日一题洛谷P8664 [蓝桥杯 2018 省 A] 付账问题c++
c++·职场和发展·蓝桥杯
旧识君1 小时前
移动端1px终极解决方案:Sass混合宏工程化实践
开发语言·前端·javascript·前端框架·less·sass·scss
熬夜苦读学习1 小时前
Linux进程信号
linux·c++·算法