QPainter 画扇形
程序员文章站
2024-03-24 10:59:04
...
void Widget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing,true);
painter.rotate(m_nRotationAngle); // 顺时针旋转坐标系
QRadialGradient gradient(0,0,90); //设置渐变
gradient.setColorAt(0,QColor(200,180,20));
gradient.setColorAt(0.5,QColor(20,220,110));
gradient.setColorAt(1.0,QColor(180,60,150));
painter.setBrush(gradient);
painter.setPen(Qt::NoPen); //设置画笔
QRectF rectf(-90,-90,90 << 1,90 << 1);
QPainterPath path;
path.arcTo(rectf,30,70);
painter.translate(width()/3,height() /3); // 偏移坐标(0,0)位置
painter.drawPath(path); //画路径(扇形)
painter.translate(0,height() /3); // 偏移坐标(0,0)位置
painter.drawPie(rectf,30*16,70*16); //画扇形
}