Important: Please read the Qt Code of Conduct -

Qwt Direct Painter Clipping [SOLVED]

  • I am currently using QwtPlotDirectPainter to plot real time data points onto a QwtPlotCurve. All data that is received from a usb device is being plotted on the graph. Here is my function that does the direct painting of the new data points:
    // paints multiple points onto the line
    // uses direct painter, no replot required
    void CustomPlot::appendActiveData(const QVector<QPointF> &points)
    // append the data point to the curve data
    CurveData *curveData = static_cast<CurveData *>(mActive->data());

    // do clipping if neccesary on specific systems
    int count = curveData->size();
    if (!canvas()->testAttribute(Qt::WA_PaintOnScreen)){
        // Depending on the platform setting a clip might be an important
        // performance issue. F.e. for Qt Embedded this reduces the
        // part of the backing store that has to be copied out - maybe
        // to an unaccelerated frame buffer device.
        const QwtScaleMap xMap = canvasMap(mActive->xAxis());
        const QwtScaleMap yMap = canvasMap(mActive->yAxis());
        // get bounding rect
        QRectF boundingRect = qwtBoundingRect(*curveData, (curveData->size() - points.size()) - 1, count - 1);
        const QRect clipRect = QwtScaleMap::transform(xMap, yMap, boundingRect).toRect();
    // use the direct painter and paint the entire line
    // this is still much faster than a 'replot'
    mDirectPainter->drawSeries(mActive, (count - points.size()) - 1, count);


    Everything works great and is extremely efficient! up until two points right next to each other on the graph have a drastic change in x value on the plot (.001mS apart on a 20 second x scale). The curve seems to not want to paint in between the two points which I think is due to the clipping region.

    I guess my real question is, how does the clipping work? I haven't really used much manual painting in Qt in general. Here is an image of the graph for a visual example what is happening.

    Edit: My issue is somewhat solved. I increased the clipping region to the size of the canvas and now there are no plot points missing during the direct paint.

  • Hello,
    I need real time clipped data plotting too. Could you please share your CustomPlot class implementation, so I can use it as an example? Or if you can't share it, at least post some references.

Log in to reply