QT QPainter绘制图片

1、绘制多边形

利用

paintEvent(QPaintEvent *event)绘图事件
void 类名::paintEvent(QPaintEvent * event)
{
    Q_UNUSED(event);
    QPainter painter(this);

    // 设置画笔颜色
     painter.setPen(QColor(0, 160, 230));
    // 反走样
    painter.setRenderHint(QPainter::Antialiasing, true);
    // 设置画笔颜色
    painter.setPen(QPen(QColor(192,192,192), 2));
    //各点坐标
    QPointF points[4] = {(10,20) ,(10, 40),  (40,80), (40, 50)};
    // 绘制多边形
    painters.drawPolygon(points, 4);
}

 

2、绘制文本

painter.drawText(x, y, QString text);

 

3、绘制直线

painter.drawLine(点1,点2);

 

3、绘制矩形

painter.drawRect(x,y,h,w);

 

4、画圆

painter.drawEllipse(x,y,x,y);

 

上一篇:leetcode-192. 统计词频


下一篇:192 DStream相关操作 - Transformations on DStreams