網(wǎng)站首頁 編程語言 正文
現(xiàn)有功能
1.用模糊功能實現(xiàn)簡易的毛玻璃效果。
2.鼠標移動無邊框窗口。
運行結(jié)果
源碼
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(); // 設(shè)置窗口背景顏色
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
相關(guān)推薦
- 2022-08-03 在C++中把字符串轉(zhuǎn)換為整數(shù)的兩種簡單方法_C 語言
- 2023-04-24 如何修改Linux內(nèi)核參數(shù)vm.swappiness_Linux
- 2023-04-17 Linux下is?not?in?the?sudoers?file的解決方案_linux shell
- 2024-04-03 linux系統(tǒng)配置nginx兩套以上的前端
- 2022-11-18 C++11正則表達式詳解(regex_match、regex_search和regex_replac
- 2023-10-14 SqlServer--get 和 post 請求 http接口
- 2022-07-18 C語言枚舉類型
- 2022-06-04 C#復雜XML反序列化為實體對象兩種方式小結(jié)_C#教程
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支