Hot to copy QGraphicsPixmapItem ?
-
Hi, I have a task to draw within scene many of symbols. So I implemented pixmap array cache to draw pixmaps for all symbols with current font size. Then I added these pixmaps(about 30000) to scene using addPixmap method. But it looks like it creates a lot of copy of same pixmaps which affects on program working time. Is here exist the way to workaround this problem? I've tried to find solution to copy QGraphicsPixmapItem to prevent copy of pixmaps but still haven't found. Thanks.
-
Hi, I have a task to draw within scene many of symbols. So I implemented pixmap array cache to draw pixmaps for all symbols with current font size. Then I added these pixmaps(about 30000) to scene using addPixmap method. But it looks like it creates a lot of copy of same pixmaps which affects on program working time. Is here exist the way to workaround this problem? I've tried to find solution to copy QGraphicsPixmapItem to prevent copy of pixmaps but still haven't found. Thanks.
@mirell
Although I do not thinkQGraphicsPixmapItemis a Qt shared object per se, theQPixmapit holds is a shared object, as per Implicit Sharing, So your pixmaps themselves should not be being copied.Then I added these pixmaps(about 30000)
I am not a graphics expert, but what do you expect speed-/space-wise if you have 30,000 pixmaps? Sounds like an awful lot to me....
-
Well if calculate asymptotics then it should not be a lot. I render FullHD image so to fill all pixels on image once(there is not collisions between letters) it takes about 2*10^6 operations while about 10^9 operations on modern processor = 1 sec. So it should be about 200 ms but I have 1 sec per frame
-
Hi and welcome to devnet,
Can you give more details about what you are doing ?
Rendering 30000 unrelated symbols is not very clear. -
Hi and welcome to devnet,
Can you give more details about what you are doing ?
Rendering 30000 unrelated symbols is not very clear.Hi @SGaist ok here the task:
I'm implementing my own text editor which can render his state to FullHD image(make snapshot itself). I have 300x100 matrix of a-z symbols. I have font size and name. So user can zoom text and change its scale. With scaling process changes elements coordinates and sizes so I'm using scene object to manage a lot of glyphs and render only FullHD crop of whole scaled scene. I also use pixmap cache of pre-drawed text symbols because it's very complicated task to draw text. So I need to add a lot of pixmaps to my scene. And here problem appears: it works too slow for me ~1 sec. So I've decided that if I can copy QGraphicsPixmapItem and pass it to scene maybe it prevents dummy copping of same pixmap data :) -
That makes things clearer but it looks a bit inefficient.
Did you check the implementation of, for example, QTextEdit ?