Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
fasten drawing of graphics items
user4592357 last edited by user4592357
i'm adding almost 26000 items to the graphics scene, and drawing them takes about 1 minute 5 seconds. is there a way to fasten the drawing? like using some cache file?
Do you really need to render all of these items all the time ?
i'm adding almost 26000 items to the graphics scene, and drawing them takes about 1 minute 5 seconds
QGraphicsView/QGraphicsScene is known to be able to handle a lot of items.
Do you trigger updates manually?
What are the items showing?
user4592357 last edited by
yes the should be (fit) in the view.
they are just
QGraphicsItems. I draw a rectangle in
p.s. i know i could use
QGraphicsRectItem, however, there was a problem with multiple inheritance from
QGraphicsRectItemthat's why i chose to draw the rect myself.
JonB last edited by
they are just QGraphicsItems. I draw a rectangle in paint().
p.s. i know i could use QGraphicsRectItem, however, there was a problem with multiple inheritance from QGraphicsItem && QGraphicsRectItem that's why i chose to draw the rect myself.
And you've checked for yourself before asking whether commenting that out makes any difference, just in case?
however, there was a problem with multiple inheritance from QGraphicsItem && QGraphicsRectItem that's why i chose to draw the rect myself.
From what you wrote you seem to have tried to inherit from both
QGraphicsRectItem, if that's the case, why ?
Buckwheat last edited by
@user4592357, what system are you draw you QGraphicsScene? I typically can handle about 100000 items and triangles in about 3 seconds when on a 1.33GHz Atom processor with 2GB of ram. This is all done while updating from GNSS and tilt sensors at 20Hz. If I am zoomed to normal working levels, I can pan the screen without lag. I use full anti-aliasing, highest quality pixmaps, full text anti-aliasing, etc.
Here is the portion with the most graphics:
@SGaist is correct, you do NOT need to inherit from QGraphicsItem when inheriting from QGraphicsItem rect! Wonderful thing those QGraphicsItems!
Have you tried to use:
in your scene?
This will speed things up but is prone to crashing if you are adding and removing items in your scene. I use 'Index' for my indexing method because I do update. I do not use setMinimumRenderSize as it will clip off more than I would like
BspTreeIndex will allow the z-ordering and the position clipping to work fully. Z-ordering is important to hide items behind other items.
There are also techniques you can use to clip yourself.
- If you have a custom QGraphicsItem, you can clip internal pieces that do not need to be drawn and properly set your bounding rect so the framework can perform gross clipping operations on the entire item.
- You can greek (draw a rectangle) text when it is not very visible since text is usually slow.
Optimize how you set pens, brushes, and fonts.
- Use setTransform more than setPos, setRotation, setScale so you can cache your transforms in custom QGraphicsItems.
I optimize my transforms. Transforms are setup and then set into the painter in my one drawing and set into graphics items as needed. This keeps updates to a minimum and is more easily optimized for saving the drawing states.
I hope some of these techniques and ideas will help you out.