yhkylin-backup-tools/kybackup/component/ringsprogressbar.cpp

58 lines
1.3 KiB
C++
Executable File

#include "ringsprogressbar.h"
#include <QPainter>
#include <QFont>
#include "../../common/mydefine.h"
RingsProgressbar::RingsProgressbar(QWidget *parent) :
QWidget(parent)
{}
RingsProgressbar::~RingsProgressbar()
{}
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(10, 10, side - 20, side - 20);
QString valueStr = QString("%1%").arg(QString::number(m_persent));
//画外圆
QPen pen = p.pen();
p.setPen(Qt::NoPen);
p.setBrush(QBrush(QColor(COLOR_LIGHT_BLUE)));
p.drawEllipse(outRect);
p.setBrush(QBrush(QColor(COLOR_BLUE)));
//画圆弧
// pen.setCapStyle(Qt::RoundCap);
// pen.setColor(QColor(COLOR_BLUE));
// p.setPen(pen);
p.drawPie(QRectF(5 , 5, side - 10, side - 10), (90-m_rotateAngle)*16, m_rotateAngle*16);
//画遮罩
p.setPen(Qt::NoPen);
p.setBrush(palette().window().color());
p.drawEllipse(inRect);
//画文字
QFont f = this->font();
f.setBold(true);
f.setPixelSize(25);
p.setFont(f);
p.setPen(QColor(COLOR_BLUE));
p.drawText(inRect, Qt::AlignCenter, valueStr);
}
void RingsProgressbar::setPersent(int persent)
{
m_persent = persent;
repaint();
}