PDA

View Full Version : How to shift the pixels of part of a QGraphicsItem?



dave2
16th September 2015, 14:31
I would like to know whether it is possible to shift part of a drawing by copying its pixels rather than redrawing it.

I work in an embedded environment, where performance is a key factor. We use Qt 4.8.

I have a set of real-time data points that I want to draw. I define the following class:


class SetOfDataPoints : public QGraphicsItem
{
public:
<constructor>
QRectF boundingRect() const { ... }
void paint(QPainter* painter,
const QStyleOptionGraphicsItem* option,
QWidget* widget = NULL) { ... }
<other methods>
};

At regular intervals, I read a new data point, add it to the instance of SetOfDataPoints, and shift the SetOfDataPoints to the left (by calling QGraphicsItem::moveBy() on the SetOfDataPoints), so the new data point becomes visible. As a result, SetOfDataPoints::paint() gets called, and in that method I have to draw the entire set of data points. The drawing currently consists only of line segments that connect the data points, but will become more elaborate in the future.

Now, it feels inefficient to redraw the whole set of data points, when most of the graph is actually just shifted to the left. I would like to shift the pixels of the unchanged part of the graph to the left, and draw only the one line segment that connects the last two points. At least I would like to try, and measure how much that improves performance.

Is there a way to do that in Qt 4.8?

anda_skoa
16th September 2015, 14:45
What you could try is to draw your data into a buffer, say a QImage, and only paint that image in paint().

That way when you get new data, you could resize the image, paint the new bits.
Or keep the size of the image, shift part of the image and paint the now vacant bits.

Cheers,
_