Reputation: 14615
I have a QGraphicsSvgItem
subclass that contains an svg that I can change based on user actions.
I can have multiple items of that type - they get created by loading an svg and setting a new svg renderer on them. I am not sure if this is the most effective way - it is how I saw it done in examples.
I store the svg, after loading, in a QByteArray
- for fast changes I do string replace on things hat can change. (I have tried to use xml but conversions to QByteAray
are too slow).
So... on load item, I do:
inFile >> m_svgContents; // which is QByteArray
setSharedRenderer(new QSvgRenderer(m_svgContents));
Then on any change, m_svgContents
gets modified, and I have to do
m_svgContents.replace(oldInfo, newInfo);
delete renderer();
setSharedRenderer(new QSvgRenderer(m_svgContents));
I just added delete renderer();
because I ran valgrind and it showed a memory leak.
It seems very heavy weight to create a new renderer each time...
Is it possible to reuse the renderer ?
The "shared renderer" would suggest that I could share it between multiple items - which is probably not useful to me because each item can have a diferent svg content - and my understanding is that each renderer is per a different svg file...
But maybe it is possible to reuse, instead of deleting and creating a new renderer, when I change the svg contents ?
Upvotes: 0
Views: 526
Reputation: 2210
And how about QSvgRenderer::load()
? It should replace current SVG content with the new one.
Upvotes: 2