QT绘制圆形进度条,不同于QPainterPath方式,直接使用 drawArc 函数效果也是出奇的好!
void Widget::paintEvent(QPaintEvent *event)
{QPainter p(this);p.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);QRect rc = this->rect();rc.adjust(20,20,-20,-20);//QPen penBackground;penBackground.setColor(Qt::gray);penBackground.setWidth(30);penBackground.setJoinStyle(Qt::RoundJoin);penBackground.setCapStyle(Qt::RoundCap);p.setPen(penBackground);p.drawArc(rc, 0, 360*16);//绘制进度条QLinearGradient gradient(0, 0, 0, 400);//QRadialGradient gradient(0, 0, 500);gradient.setColorAt(0, QColor("#ffffff"));gradient.setColorAt(1.0, QColor("#ff6633"));//int startAngle = 90*16;int spanAngle = -270*16;QPen penForeground;penForeground.setBrush(gradient);penForeground.setWidth(20);penForeground.setJoinStyle(Qt::RoundJoin);penForeground.setCapStyle(Qt::RoundCap);p.setPen(penForeground);p.drawArc(rc, startAngle, spanAngle);
}
效果图