Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Clipping & Viewports with QGraphicsView and QGraphicsScene
cuddlykittens11 last edited by
I'm working on a project right now that has extensive use of the QGraphicsView framework. I have this scene where I only want to display/draw items that are within the bounds (0, 0, 5000, 100) ((left, top, right, bottom)). I currently have an item that has a negative x position, but half of it is still within the bounds.
My View is drawing the whole item when I only want to draw half of it. I want it clipped along the Y-origin. How do I do this?
Asperamanca last edited by
One easy way would be to create an invisible parent item for the items you want to clip. Give it the clip rect you want as boundingRect, and add the "ItemClipsChildrenToShape" flag.
You can also use the flag ItemClipsToShape to restrict a single item to it's own shape.
Finally, you can always clip manually by setting clip rects or regions on the painter in the respective paint() methods.