Unsolved fasten drawing of graphics items
-
hi,
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? -
Hi,
Do you really need to render all of these items all the time ?
-
@user4592357 said in fasten drawing of graphics items:
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? -
@SGaist,
yes the should be (fit) in the view.@raven-worx,
they are justQGraphicsItem
s. I draw a rectangle inpaint()
.
p.s. i know i could useQGraphicsRectItem
, however, there was a problem with multiple inheritance fromQGraphicsItem
&&QGraphicsRectItem
that's why i chose to draw the rect myself. -
@raven-worx,
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?
-
@user4592357 said in fasten drawing of graphics items:
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
QGraphicsItem
andQGraphicsRectItem
, if that's the case, why ?QGraphicsRectItem
is aQGraphicsItem
. -
@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:
setItemIndexMethod (BspTreeIndex);
or
setMinimumRenderSize (...);
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.