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. GraphicsView: Artifacts after reducing boundingRect size - scene()->update() does nothing

GraphicsView: Artifacts after reducing boundingRect size - scene()->update() does nothing

Scheduled Pinned Locked Moved Unsolved General and Desktop
graphicsviewpainting
11 Posts 3 Posters 3.7k 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.
  • A Offline
    A Offline
    Asperamanca
    wrote on last edited by Asperamanca
    #1

    I have a scene which consists of a background, two grids (vertical and horizontal) and a line plot. Each is a separate, custom QGraphicsItem.

    I can scale the whole X-axis. When that happens, I call "prepareGeometryChange" and re-calculate the boundingRect for the line plot.

    Now, when I change the scaling so the line plot becomes more narrow, a part of the scene that was previously covered by the line plot should now only display background and grid. However, I see the remains of the "old" line plot painting all over the place.

    I have checked that the boundingRect has the correct size, by replacing the paint code with (basically) painter->drawRect(boundingRect()); The size is exactly as expected, before and after scaling the x-axis.

    I have double-checked that prepareGeometryChange() is called before I actually recalculate the boundingRect, so that it would get the old boundingRect if needed.

    And now it gets strange: I have tried to force repainting by calling either linePlot->update(); (before or after the change to the boundingRect), or even by calling scene->update() or scene->invalidate()
    Nothing! These calls do not seem to have any effect!

    However, cover the window with something else, and show it again, and everything is displayed as it should be.
    I also checked that none of the items use caching (setCachingMode).

    Any ideas what could prevent a scene()->update() from repainting the scene?

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

      Hi,

      That's maybe related to the viewport update mode.

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

      A 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        That's maybe related to the viewport update mode.

        A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        @SGaist said in GraphicsView: Artifacts after reducing boundingRect size - scene()->update() does nothing:

        Hi,

        That's maybe related to the viewport update mode.

        Good hint! Viewport update modes Minimal and Smart show the incorrect repaint, while viewport modes Full and BoundingRect display correctly.

        The documentation on the modes is a bit thin...why would Minimal and Smart conclude that an area does not need to redraw, even though I explicitly call update() on the item?

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

          Sorry, I can't answer that one, a look at the algorithm used might give you more information about that.

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

          A 1 Reply Last reply
          0
          • SGaistS SGaist

            Sorry, I can't answer that one, a look at the algorithm used might give you more information about that.

            A Offline
            A Offline
            Asperamanca
            wrote on last edited by
            #5

            @SGaist said in GraphicsView: Artifacts after reducing boundingRect size - scene()->update() does nothing:

            Sorry, I can't answer that one, a look at the algorithm used might give you more information about that.

            I have tried, but debugging this part of code is not easily done, because switching between debugger and applications triggers invalidates and repaints.
            Also, watching regions in the debugger is not easily done...

            1 Reply Last reply
            0
            • BjornWB Offline
              BjornWB Offline
              BjornW
              wrote on last edited by BjornW
              #6

              Do you make sure to paint inside the bounding rect? If you have, let's say, a 200x200 rect that you draw with 2p brush width, the bounding rect is actually 202x202.

              Usually this means, if you want to draw a 200x200 rect with 2p brush width, you should draw a 198x198 rect to keep everything inside the 200x200 bounding rect.

              A 1 Reply Last reply
              0
              • BjornWB BjornW

                Do you make sure to paint inside the bounding rect? If you have, let's say, a 200x200 rect that you draw with 2p brush width, the bounding rect is actually 202x202.

                Usually this means, if you want to draw a 200x200 rect with 2p brush width, you should draw a 198x198 rect to keep everything inside the 200x200 bounding rect.

                A Offline
                A Offline
                Asperamanca
                wrote on last edited by
                #7

                @BjornW said in GraphicsView: Artifacts after reducing boundingRect size - scene()->update() does nothing:

                Do you make sure to paint inside the bounding rect? If you have, let's say, a 200x200 rect that you draw with 2p brush width, the bounding rect is actually 202x202.

                Usually this means, if you want to draw a 200x200 rect with 2p brush width, you should draw a 198x198 rect to keep everything inside the 200x200 bounding rect.

                I know the artifacts I get when I do this mistake: A thin border around the area of the old bounding rect. However, in my case the artifacts practically fill the old bounding rect.
                Also, all my pens are hairline (1 px cosmetic), and GraphicsView normally takes that one pixel around the boundingRect into account, if memory serves me.

                1 Reply Last reply
                0
                • BjornWB Offline
                  BjornWB Offline
                  BjornW
                  wrote on last edited by
                  #8

                  Can you post code?

                  I do not think that QGraphicsScene takes anything into account regarding brushes etc.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    Asperamanca
                    wrote on last edited by
                    #9

                    For one thing, here is how it looks with artefacts:

                    Screenshot
                    Each of the colorful rectangles is a GraphicsItem. The "old" boundingRect has a width of 981 px. The "new" boundingRect is half as wide, and slightly to the left of the center. All colored areas above and below the dashed line should be black with a gray grid.

                    The paint code is simple. This is not the original code, but sufficient to cause the effect.

                        painter->setPen(Qt::NoPen);
                        painter->setBrush(QBrush(m_LinePen.color()));
                        painter->drawRect(boundingRect());
                    
                    1 Reply Last reply
                    0
                    • BjornWB Offline
                      BjornWB Offline
                      BjornW
                      wrote on last edited by
                      #10

                      How do you update the bounding rect?

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        Asperamanca
                        wrote on last edited by Asperamanca
                        #11

                        By calling "prepareGeometryChange()" and then changing the fundamental parameters that are used in my overload of boundingRect()

                        1 Reply Last reply
                        0

                        • Login

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