-
Notifications
You must be signed in to change notification settings - Fork 7
/
progressbutton.cpp
58 lines (44 loc) · 1.25 KB
/
progressbutton.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
/**
* Progress Button
* @brief 进度条按钮
* @anchor Ho229
* @date 2021/2/22
*/
#include "progressbutton.h"
#include <QPainter>
ProgressButton::ProgressButton(QWidget *parent, const QString &style) :
QPushButton(parent)
{
m_pen.setCapStyle(Qt::RoundCap);
m_pen.setWidth(3);
m_pen.setColor(QColor(69, 198, 214));
this->setStyleSheet(style);
}
ProgressButton::~ProgressButton()
{
}
void ProgressButton::setValue(int value)
{
value = qMin(value, m_maximun);
if(value == m_value) // No changed
return;
m_value = value;
emit valueChanged(value);
this->repaint();
}
void ProgressButton::paintEvent(QPaintEvent *event)
{
QPushButton::paintEvent(event);
int drawAngle = static_cast<int>(
static_cast<qreal>(m_value) / (m_maximun - m_minimun) * 360);
if(drawAngle <= 0)
return;
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(m_pen);
QRect rect;
int min = qMin(this->width(), this->height()) - m_pen.width() * 2;
rect.setSize(QSize(min, min));
rect.moveCenter(this->rect().center());
painter.drawArc(rect, TransAngle(90), TransAngle(90 - drawAngle));
}