forked from Longxr/QtCustomProgressbar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ringsprogressbar.cpp
47 lines (40 loc) · 1.14 KB
/
ringsprogressbar.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
#include "ringsprogressbar.h"
#include <QPainter>
RingsProgressbar::RingsProgressbar(QWidget *parent) : QWidget(parent),
m_rotateAngle(0),
m_persent(0)
{
}
void RingsProgressbar::setPersent(int persent)
{
if(persent != m_persent)
{
m_persent = persent;
update();
}
}
void RingsProgressbar::paintEvent(QPaintEvent *)
{
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
m_rotateAngle = 360*m_persent/100;
int side = qMin(width(), height());
QRectF outRect(0, 0, side, side);
QRectF inRect(20, 20, side-40, side-40);
QString valueStr = QString("%1%").arg(QString::number(m_persent));
//画外圆
p.setPen(Qt::NoPen);
p.setBrush(QBrush(QColor(97, 117, 118)));
p.drawEllipse(outRect);
p.setBrush(QBrush(QColor(255, 107, 107)));
p.drawPie(outRect, (90-m_rotateAngle)*16, m_rotateAngle*16);
//画遮罩
p.setBrush(palette().window().color());
p.drawEllipse(inRect);
//画文字
QFont f = QFont("Microsoft YaHei", 15, QFont::Bold);
p.setFont(f);
p.setFont(f);
p.setPen(QColor("#555555"));
p.drawText(inRect, Qt::AlignCenter, valueStr);
}