-
Notifications
You must be signed in to change notification settings - Fork 9
/
ShadowEffectWidget.cpp
34 lines (31 loc) · 1.03 KB
/
ShadowEffectWidget.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
/**
* 去掉标题之后添加边框阴影
*
* ShadowEffectWidget.cpp
* 使用Qt的QGraphicsDropShadowEffect类来实现边框阴影cpp文件。
*
* FlyWM_
* GitHub: https://github.com/FlyWM
* CSDN: https://blog.csdn.net/a844651990
*
*/
#include <QGraphicsDropShadowEffect>
#include <QLayout>
#include "ShadowEffectWidget.h"
ShadowEffectWidget::ShadowEffectWidget(QWidget *parent)
: QWidget(parent)
{
resize(400, 300);
setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
QWidget *pCentralWidget = new QWidget(this);
pCentralWidget->setStyleSheet("background-color: white");
QHBoxLayout *pLayout = new QHBoxLayout(this);
pLayout->addWidget(pCentralWidget);
pLayout->setContentsMargins(20, 20, 20, 20);
QGraphicsDropShadowEffect *pEffect = new QGraphicsDropShadowEffect(pCentralWidget);
pEffect->setOffset(0, 0);
pEffect->setColor(QColor(QStringLiteral("black")));
pEffect->setBlurRadius(30);
pCentralWidget->setGraphicsEffect(pEffect);
}