Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. fasten drawing of graphics items
Qt 6.11 is out! See what's new in the release blog

fasten drawing of graphics items

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 5 Posters 1.5k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    user4592357
    wrote on last edited by user4592357
    #1

    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?

    raven-worxR 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • U user4592357

        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?

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

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

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        1
        • U Offline
          U Offline
          user4592357
          wrote on last edited by
          #4

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

          JonBJ 1 Reply Last reply
          0
          • U user4592357

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

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • BuckwheatB Offline
                BuckwheatB Offline
                Buckwheat
                wrote on last edited by
                #7

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

                Dave Fileccia

                1 Reply Last reply
                3

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved