Important: Please read the Qt Code of Conduct -

DrawLine using QPaintedItem is not proper

  • Hi ,
    I am trying to draw wave forms using QPaintedItem with drawLine .
    When i try to draw continuous line with real time data i can see some pixels are getting missed .

    With same data if i draw using charview (lineseries,valueAxis) drawing is perfect.

    can somebody help what can be issue ? Should i set anything before drawing ?

    I am using QPen to draw right now .

    Thanks in advance .

  • Lifetime Qt Champion

    Its hard to guess at with no code but
    maybe its due to double to int capping and not doing rounding.

    Can you show your draw code ?

  • void DrawGraph::updateGraph(qreal x, qreal y)
    QPointF newpoint(xPlotPosition,yPlotPosition);
    line = QLineF(lastPoint, newpoint);
    lastPoint = newpoint;



    void DrawGraph::paint(QPainter *painter)

    void DrawGraph::drawGraph(QPainter *painter)

    painter->drawLine(line); // QLineF line;


  • Lifetime Qt Champion

    Seems fine
    what types are xPlotPosition,yPlotPosition ?

  • xPlotPosition and yPlotPosition are qreal type

  • Lifetime Qt Champion


    I would inspect newpoint.x() and see how much its truncated
    comapred to the xPlotPosition

    Also maybe turn on antialiasing for QPainter

    but it really looks like it get truncated.

Log in to reply