Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

(SOLVED) Draw arc into qgraphicsview



  • I have:
    Graphicsview dove;
    Graphicsscene scene;
    With
    dove->setscene(scene).
    if I want to draw an ellipse can do(and circle)
    dove.scene.addellipse(........)
    if I want to draw an rectangle can do
    dove.scene.addrect(........)
    But if I want to draw an arc as I do?
    dove.scene.addarc not exist.



  • You can create a QGraphicsPathItem, and set a QPainterPath that contains the arc you want to draw (use QPainterPath::moveTo and QPainterPath::arcTo)



  • I tried but does not work as I would like;
    I would use drawArc of QPainter;
    Someone could tell me how can I do?



  • You can always create your own QGraphicsItem: Derive from QGraphicsItem, and implement paint and boundingRect.



  • I solved this way:
    @ QPicture pi;
    QPainter p(&pi);
    p.setRenderHint(QPainter::Antialiasing);
    p.setPen(QPen(Qt::black, 1));
    p.drawLine(x1,y1,x2,y2);
    p.end();
    dove->setPicture(pi);
    @

    where dove is a QLabels



  • You could use the same approach with a QPixmap and a QGraphicsPixmapItem. But if your current approach works well for you, that's certainly ok.


Log in to reply