-
Notifications
You must be signed in to change notification settings - Fork 15
/
WinTransparent.cpp
54 lines (45 loc) · 1.44 KB
/
WinTransparent.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "WinTransparent.h"
#include <QMouseEvent>
#include <QDebug>
#include <QBoxLayout>
#include <QGraphicsEffect>
#include <QGraphicsBlurEffect>
WinTransparent::WinTransparent(QWidget *parent)
: QWidget(parent)
, m_posStart(QPoint(0, 0))
, m_isMoveWindow(false)
{
init();
}
void WinTransparent::init()
{
setWindowFlags(Qt::X11BypassWindowManagerHint); // x11 直接绘制,无边框,无影阴影,总是置顶
// setAttribute(Qt::WA_TranslucentBackground);
// setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
// setWindowFlags(windowFlags() | Qt::FramelessWindowHint /*| Qt::ToolTip | Qt::FramelessWindowHint | Qt::Dialog*/);
// setWindowOpacity(1); // 透明度
// resize(400, 600);
// setAttribute(Qt::WA_TranslucentBackground);
// QGraphicsBlurEffect *blur = new QGraphicsBlurEffect();
// blur->setBlurRadius(0.5);
// blur->setBlurHints(QGraphicsBlurEffect::QualityHint);
// setGraphicsEffect(blur);
}
void WinTransparent::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
m_isMoveWindow = true;
m_posStart = event->pos();
}
}
void WinTransparent::mouseMoveEvent(QMouseEvent *event)
{
if (m_isMoveWindow)
move(event->pos() - m_posStart + pos());
}
//void WinTransparent::mouseReleaseEvent(QMouseEvent *event)
//{
// if (event->button() == Qt::LeftButton)
// m_isMoveWindow = false;
// qDebug()<<"--------------->111";
//}