drawing plot lines on QGraphicsScene

2019-09-11 14:27发布

问题:

I designed a QGraphicsScene like a graph with scale at both axis and with the data i able to plot points on the the scene using QGraphicsItem. but I don’t know which method will be suitable for connecting the points so it can be look like a graph plotted. PainterPath or some other specific things ?

回答1:

I'd say QPainter::drawPolyline() is a good option (or QPainterPath::addPolygon). You can use QPolygonF to contain your points. Then you just pass this to the QPainter's drawPolyline function.

QPolygonF polyline;   
polyline.append(QPointF(x, y)); // add your points
painter->drawPolyline(polyline);

or

QPainterPath painterPath;
painterPath.addPolygon(polyline);