HcyJerry007
frostace07
采纳率0%
2018-05-13 12:40

Qt 使用QPainter绘图问题

20

我在mainwindow里定义了成员函数drawArc,用来画一个镂空的扇形

void drawArc(QLabel *label,QPixmap pixmap, QPainter *painter, QColor color, qreal startangle , qreal spanangle )
    {
    //---------------------------------------------------------------------------------------
    QPixmap tempPixmap = pixmap;                                // 定义画布
    painter->begin(&tempPixmap);
    painter->setRenderHint(QPainter::Antialiasing,true);
    painter->setPen(Qt::NoPen);                                 // 没有轮廓
    //----------------------------------------------------------------------------------------
    QRectF rect(0,0,pixmap.width(),pixmap.width());      //用来画扇形的正方形
    painter->setBrush(color);                                   // 设置颜色
    int width = pixmap.width()/6;
    //int height = rect->height()/6;
    QPainterPath path;

    path.arcTo(rect, startangle, spanangle);
    QPainterPath subPath;
    subPath.addEllipse(rect.adjusted(width, width, -width, -width));

    painter->drawPath(path - subPath);
    painter->end();
    label->setPixmap(tempPixmap);
}

调用是这样写的:
drawArc(callerLabel,pixmap,&painter,color[0],0,180);

图片说明

最后结果出来确实这样的,求问高手!!!急!!!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

相关推荐