-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathroundscrollarea.cpp
More file actions
39 lines (31 loc) · 933 Bytes
/
Copy pathroundscrollarea.cpp
File metadata and controls
39 lines (31 loc) · 933 Bytes
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
// SPDX-FileCopyrightText: 2018 - 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "roundscrollarea.h"
#include <QPainter>
#include <QPainterPath>
#include <DPalette>
#include <DPaletteHelper>
DWIDGET_USE_NAMESPACE
RoundScrollArea::RoundScrollArea(QWidget *parent)
: QScrollArea(parent)
, m_radius(18)
{
DPalette pa = DPaletteHelper::instance()->palette(this);
pa.setBrush(DPalette::Window, Qt::transparent);
DPaletteHelper::instance()->setPalette(this, pa);
}
void RoundScrollArea::setRadius(int radius)
{
m_radius = radius;
update();
}
void RoundScrollArea::paintEvent(QPaintEvent *e)
{
QPainter painter(viewport());
painter.setRenderHint(QPainter::Antialiasing);
QPainterPath path;
path.addRoundedRect(viewport()->rect(), m_radius, m_radius);
painter.setClipPath(path);
painter.fillPath(path, palette().window());
}