Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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?


  • Lifetime Qt Champion

    Hi,

    Do you really need to render all of these items all the time ?


  • Moderators

    @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 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.



  • @user4592357

    @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?


  • Lifetime Qt Champion

    @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 and QGraphicsRectItem, if that's the case, why ? QGraphicsRectItem is a QGraphicsItem.



  • @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:0_1526413777169_6101fb73-7f46-41f4-b282-d71e1bf2909c-image.png

    @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.


Log in to reply