forked from Longxr/QtCustomProgressbar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathringsmapprogressbar.cpp
47 lines (38 loc) · 1.16 KB
/
ringsmapprogressbar.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
#include "ringsmapprogressbar.h"
#include <QPainter>
RingsMapProgressbar::RingsMapProgressbar(QWidget *parent) : QWidget(parent),
m_rotateAngle(0),
m_persent(0)
{
}
void RingsMapProgressbar::setPersent(int persent)
{
if(persent != m_persent)
{
m_persent = persent;
update();
}
}
void RingsMapProgressbar::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);
QPixmap backMap = QPixmap(":/resource/progress_back.png");
p.drawPixmap(outRect, backMap, outRect);
//画内弧
QPixmap frontMap = QPixmap(":/resource/progress_front.png");
p.setBrush(QBrush(frontMap));
p.drawPie(outRect, (90-m_rotateAngle)*16, m_rotateAngle*16);
//画文字
QFont f = QFont("Microsoft YaHei", 15, QFont::Bold);
p.setFont(f);
p.setPen(QColor("#DDDDDD"));
p.drawText(inRect, Qt::AlignCenter, valueStr);
}