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. QGraphicsView cache problem
QtWS25 Last Chance

QGraphicsView cache problem

Scheduled Pinned Locked Moved Solved General and Desktop
qgraphicsviewbackgroundgraphics
7 Posts 3 Posters 3.5k Views
  • 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.
  • 0 Offline
    0 Offline
    0...-5
    wrote on 14 Jul 2016, 18:35 last edited by
    #1

    I am using QGraphicsView/QGraphicsScene to render a set of dynamic items (markers)
    sample
    During for about 15 seconds everything is ok. But then appears an abnormal graphics artifact - parts of markers or even the hole of them do not disappear when I call hide() method
    artifact
    It seems that the problem is in view's cache, cause when I call resetCachedContent() this traces disappear.
    Is there a way to manipulate views's cache? Is there a way to reset cached content right after cache is overflown?

    J 1 Reply Last reply 14 Jul 2016, 20:32
    0
    • 0 0...-5
      14 Jul 2016, 18:35

      I am using QGraphicsView/QGraphicsScene to render a set of dynamic items (markers)
      sample
      During for about 15 seconds everything is ok. But then appears an abnormal graphics artifact - parts of markers or even the hole of them do not disappear when I call hide() method
      artifact
      It seems that the problem is in view's cache, cause when I call resetCachedContent() this traces disappear.
      Is there a way to manipulate views's cache? Is there a way to reset cached content right after cache is overflown?

      J Offline
      J Offline
      Joel Bodenmann
      wrote on 14 Jul 2016, 20:32 last edited by
      #2

      Is it possible that the QGraphicsItem::boundingRect() implementation is wrong (the rect is too small)? Note that when you paint a rectangle, half the pen width is OUTSIDE of the rectangle. The bounding rect must include that.

      Other than that, you might want to have a look at QGraphicsView::ViewportUpdateMode.

      Industrial process automation software: https://simulton.com
      Embedded Graphics & GUI library: https://ugfx.io

      0 1 Reply Last reply 15 Jul 2016, 06:05
      0
      • J Joel Bodenmann
        14 Jul 2016, 20:32

        Is it possible that the QGraphicsItem::boundingRect() implementation is wrong (the rect is too small)? Note that when you paint a rectangle, half the pen width is OUTSIDE of the rectangle. The bounding rect must include that.

        Other than that, you might want to have a look at QGraphicsView::ViewportUpdateMode.

        0 Offline
        0 Offline
        0...-5
        wrote on 15 Jul 2016, 06:05 last edited by
        #3

        @Joel-Bodenmann no, bounding rect is big enough, I have tested expanded rect too - it doesn't fix the problem.
        But the second your advice does! I have set setViewportUpdateMode(QGraphicsView::FullViewportUpdate); and no traces were kept on the scene. Thanks a lot!
        I hope that this mode doesn't lead to much overhead and performance cost.

        R 1 Reply Last reply 15 Jul 2016, 06:37
        0
        • 0 0...-5
          15 Jul 2016, 06:05

          @Joel-Bodenmann no, bounding rect is big enough, I have tested expanded rect too - it doesn't fix the problem.
          But the second your advice does! I have set setViewportUpdateMode(QGraphicsView::FullViewportUpdate); and no traces were kept on the scene. Thanks a lot!
          I hope that this mode doesn't lead to much overhead and performance cost.

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 15 Jul 2016, 06:37 last edited by
          #4

          @0...-5
          what kind of QGraphicsItem are your items?
          In case you implemented a custom item you may want to show the implementation?

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

          0 1 Reply Last reply 15 Jul 2016, 07:19
          0
          • R raven-worx
            15 Jul 2016, 06:37

            @0...-5
            what kind of QGraphicsItem are your items?
            In case you implemented a custom item you may want to show the implementation?

            0 Offline
            0 Offline
            0...-5
            wrote on 15 Jul 2016, 07:19 last edited by
            #5

            @raven-worx It is a custom item, but it's design is quite simple. It is based on a QPainterPath, which is drawn with some brush and Qt::NoPen. I don't think implementation plays a key role here.

            R 1 Reply Last reply 15 Jul 2016, 07:57
            0
            • 0 0...-5
              15 Jul 2016, 07:19

              @raven-worx It is a custom item, but it's design is quite simple. It is based on a QPainterPath, which is drawn with some brush and Qt::NoPen. I don't think implementation plays a key role here.

              R Offline
              R Offline
              raven-worx
              Moderators
              wrote on 15 Jul 2016, 07:57 last edited by
              #6

              @0...-5 said:

              I don't think implementation plays a key role here.

              I don't share this opinion.

              Whats so special about your custom item, why do you need it?
              To check your implementation you can try to insert QGraphicsPathItem instead. If the issues are gone it is your implementation. If not then the cause is somewhere else.

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

              0 1 Reply Last reply 15 Jul 2016, 08:33
              0
              • R raven-worx
                15 Jul 2016, 07:57

                @0...-5 said:

                I don't think implementation plays a key role here.

                I don't share this opinion.

                Whats so special about your custom item, why do you need it?
                To check your implementation you can try to insert QGraphicsPathItem instead. If the issues are gone it is your implementation. If not then the cause is somewhere else.

                0 Offline
                0 Offline
                0...-5
                wrote on 15 Jul 2016, 08:33 last edited by
                #7

                @raven-worx I mean drawing part is quite simple, but there is a stuff QGraphicsPathItem doesn't provide, so I had to implement my own class. I will make some experiments with QGraphicsPathItem later, but for now viewportUpdateMode solves an issue.

                1 Reply Last reply
                0

                2/7

                14 Jul 2016, 20:32

                topic:navigator.unread, 5
                • Login

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