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);