Important: Please read the Qt Code of Conduct -

Painting GraphicsItems directly

  • I am implementing a kind of scroll area that can be used within a GraphicsScene. It consists of a canvas, which contains all the items to show, and a viewport, which shows a part (or all) of the canvas, and handles zooming as well. In short, canvas is to viewport as QGraphicsScene is to QGraphicsView. Just that everything is completely inside a GraphicsScene.

    Of course, I could attach multiple viewports to a single canvas. Therefore, I cannot simply reparent the canvas when assigning it to a viewport.

    Now how do I paint the part of the canvas that should be visible inside the viewport?

    My idea was to implement the viewport's paint method, and directly paint the canvas by calling it's paint method (after setting all the necessary transformations on the painter).
    However, this method only paints the canvas itself, but not the items contained within. Because the paint() method does not itself recursively call the paint methods of the children.

    How do I paint a whole tree (i.e. an item including all it's children) to a QPainter?

Log in to reply