View Full Version : how to keep the last elements of QPainterPath

10th September 2015, 15:41
I am drawing with QPainterPath at regular times. ALl in all, I have a slot called every 100 ms that updates the position of the tip adding a new point to the path. How could I keep the last 1000 points and discard and free the memory of the older ones?

8th October 2015, 12:32
No go with this one?

8th October 2015, 16:39
The only way I've thought of achieving this is by obtaining the path and modifying all its items. Something like:

QPainterPath p = item->path();
for(int i = 0; i < p.elementCount()-1; i++)
auto e = p.elementAt(i+1);
p.setElementPositionAt(i, e.x(), e.y());

But it's kind of lame to do it like this. If only there was the possibility of deleting the first or last item we could do it too.

Since I haven't found any documentation on how to do this and a few posts asking similar things without answer I'm considering building the path myself by storing a vector of lines, but i guess that would be costly too. Any help is appreciated. Is there a way to access the internal vector of the path?