網站首頁 編程語言 正文
現有功能
1.用模糊功能實現簡易的毛玻璃效果。
2.鼠標移動無邊框窗口。
運行結果
源碼
frosted_glass_label.h
#ifndef FROSTEDGLASSLABEL_H
#define FROSTEDGLASSLABEL_H
#include <QWidget>
#include <QLabel>
#include <QMouseEvent>
class FrostedGlassLabel : public QLabel
{
Q_OBJECT
public:
FrostedGlassLabel(QWidget *parent = nullptr);
~FrostedGlassLabel();
protected:
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
private:
void setBackgroundColor(); // 設置窗口背景顏色
void blur(); // 模糊
private:
float startX; // 這兩個變量用來移動窗口
float startY;
};
#endif // FROSTEDGLASSLABEL_H
frosted_glass_label.cpp
#include "frosted_glass_label.h"
#include <Qt>
#include <QPalette>
#include <QColor>
#include <QGraphicsBlurEffect>
FrostedGlassLabel::FrostedGlassLabel(QWidget *parent)
: QLabel(parent)
{
this->resize(300, 100);
this->setWindowFlags(Qt::FramelessWindowHint);
this->setBackgroundColor();
this->blur();
}
FrostedGlassLabel::~FrostedGlassLabel()
{
}
void FrostedGlassLabel::setBackgroundColor() {
QPalette palette;
palette.setColor(QPalette::Background, QColor(245, 245, 245, 250));
this->setPalette(palette);
this->setAutoFillBackground(true);
}
void FrostedGlassLabel::blur() {
QGraphicsBlurEffect *blur = new QGraphicsBlurEffect();
blur->setBlurRadius(30);
blur->setBlurHints(QGraphicsBlurEffect::QualityHint);
this->setGraphicsEffect(blur);
}
void FrostedGlassLabel::mousePressEvent(QMouseEvent *event) {
QLabel::mousePressEvent(event);
this->startX = event->x();
this->startY = event->y();
}
void FrostedGlassLabel::mouseMoveEvent(QMouseEvent *event) {
QLabel::mouseMoveEvent(event);
float disX = event->x() - this->startX;
float disY = event->y() - this->startY;
this->move(this->x()+disX, this->y()+disY);
}
main.cpp
#include "frosted_glass_label.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
FrostedGlassLabel w;
w.show();
return a.exec();
}
原文鏈接:https://blog.csdn.net/La_vie_est_belle/article/details/125102683
相關推薦
- 2022-11-14 C#中對集合排序的三種方式_C#教程
- 2022-10-14 Ubuntu在GitHub中配置SSH Key
- 2022-10-29 編寫字符設備驅動控制樹莓派io口
- 2022-03-23 C++實現AVL樹的基本操作指南_C 語言
- 2024-03-23 spring boot 使用AOP實現是否已登錄檢測
- 2023-04-01 C++11中的智能指針和垃圾回收使用_C 語言
- 2022-12-27 python的ImageTk.PhotoImage大坑及解決_python
- 2023-01-15 rust異步編程詳細講解_Rust語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支