Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved QGraphicsView cache problem

    General and Desktop
    qgraphicsview background graphics
    3
    7
    2746
    Loading More Posts
    • 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
      0...-5 last edited by

      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?

      Joel Bodenmann 1 Reply Last reply Reply Quote 0
      • Joel Bodenmann
        Joel Bodenmann @0...-5 last edited by

        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 Reply Quote 0
        • 0
          0...-5 @Joel Bodenmann last edited by

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

          raven-worx 1 Reply Last reply Reply Quote 0
          • raven-worx
            raven-worx Moderators @0...-5 last edited by

            @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 Reply Quote 0
            • 0
              0...-5 @raven-worx last edited by

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

              raven-worx 1 Reply Last reply Reply Quote 0
              • raven-worx
                raven-worx Moderators @0...-5 last edited by

                @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 Reply Quote 0
                • 0
                  0...-5 @raven-worx last edited by

                  @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 Reply Quote 0
                  • First post
                    Last post