目录现有功能运行结果源码frosted_glass_label.hfrosted_glass_label.cppmain.cpp现有功能 1.用模糊功能实现简易的毛玻璃效果。 2.鼠
1.用模糊功能实现简易的毛玻璃效果。
2.鼠标移动无边框窗口。
#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
#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);
}
#include "frosted_glass_label.h"
#include <QApplication>
int main(int arGC, char *argv[])
{
QApplication a(argc, argv);
FrostedGlassLabel w;
w.show();
return a.exec();
}
到此这篇关于Qt实现简易毛玻璃效果的示例代码的文章就介绍到这了,更多相关Qt毛玻璃效果内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: Qt实现简易毛玻璃效果的示例代码
本文链接: https://www.lsjlt.com/news/150765.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0