forked from Longxr/QtCustomProgressbar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradiusprogressbar.cpp
35 lines (28 loc) · 1.01 KB
/
radiusprogressbar.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
#include "radiusprogressbar.h"
#include <QPainter>
RadiusProgressBar::RadiusProgressBar(QWidget *parent) : QProgressBar(parent)
{
setMinimum(0);
setMaximum(100);
setValue(0);
}
void RadiusProgressBar::paintEvent(QPaintEvent *)
{
QPainter p(this);
QRect rect = QRect(0, 0, width(), height()/2);
QRect textRect = QRect(0, height()/2, width(), height()/2);
const double k = (double)(value() - minimum()) / (maximum()-minimum());
int x = (int)(rect.width() * k);
QRect fillRect = rect.adjusted(0, 0, x-rect.width(), 0);
QString valueStr = QString("%1%").arg(QString::number(value()));
QPixmap buttomMap = QPixmap(":/resource/radius_back.png");
QPixmap fillMap = QPixmap(":/resource/radius_front.png");
//画进度条
p.drawPixmap(rect, buttomMap);
p.drawPixmap(fillRect, fillMap, fillRect);
//画文字
QFont f = QFont("Microsoft YaHei", 15, QFont::Bold);
p.setFont(f);
p.setPen(QColor("#555555"));
p.drawText(textRect, Qt::AlignCenter, valueStr);
}