Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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 .
    548aaaf4-dcec-47a3-a1bc-ba97819e937d-image.png


  • Lifetime Qt Champion

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

    rect.setRect(newpoint.x()-2,yGraphStartPixel,30,this->height());
    update(rect);
    

    }

    void DrawGraph::paint(QPainter *painter)
    {
    this->drawGraph(painter);
    }

    void DrawGraph::drawGraph(QPainter *painter)
    {
    painter->setPen(QPen(Qt::green,2));

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

    }


  • Lifetime Qt Champion

    Hi
    Seems fine
    what types are xPlotPosition,yPlotPosition ?



  • xPlotPosition and yPlotPosition are qreal type


  • Lifetime Qt Champion

    @Ajay-Krishna

    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