QPainter 画扇形

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);  //画扇形

}


QPainter 画扇形_第1张图片

你可能感兴趣的:(C++语法)