-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshadowwidget.cpp
69 lines (59 loc) · 1.72 KB
/
shadowwidget.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "shadowwidget.h"
#include <QPainter>
#include <QMouseEvent>
#include <QStyleOption>
#include <qmath.h>
ShadowWidget::ShadowWidget(QWidget *parent) :
QWidget(parent), m_mousePress(false)
{
setWindowFlags(Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint|Qt::Tool);
//this->setObjectName("basewidget");
// setAttribute(Qt::WA_TranslucentBackground);
}
void ShadowWidget::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
//加阴影,因为扁平化去掉
// QPainterPath path;
// path.setFillRule(Qt::WindingFill);
// path.addRect(10, 10, this->width()-20, this->height()-20);
// QPainter painter(this);
// painter.setRenderHint(QPainter::Antialiasing, true);
// painter.fillPath(path, QBrush(Qt::white));
// QColor color(0, 0, 0, 50);
// for(int i=0; i<10; i++)
// {
// QPainterPath path;
// path.setFillRule(Qt::WindingFill);
// path.addRect(10-i, 10-i, this->width()-(10-i)*2, this->height()-(10-i)*2);
// color.setAlpha(150 - qSqrt(i)*50);
// painter.setPen(color);
// painter.drawPath(path);
// }
}
void ShadowWidget::mousePressEvent(QMouseEvent *event)
{
//只能是鼠标左键移动和改变大小
if(event->button() == Qt::LeftButton)
{
m_mousePress = true;
}
//窗口移动距离
m_movePoint = event->globalPos() - pos();
}
void ShadowWidget::mouseReleaseEvent(QMouseEvent *)
{
m_mousePress = false;
}
void ShadowWidget::mouseMoveEvent(QMouseEvent *event)
{
//移动窗口
if(m_mousePress)
{
QPoint movePpos = event->globalPos();
move(movePpos - m_movePoint);
}
}