Hi,
I have some problems with QGraphicsView.fitInView method.
I'm drawing some items on the scene and fit it to the view. That's fine. (fig0.png in the attachments)
Then I want to move all the items to different points. Doing this, scene.itemsBoundingRect() is calculated correctly. I update the sceneRect with:
self.scene().setSceneRect(self.scene().itemsBoundingRect())
self.scene().setSceneRect(self.scene().itemsBoundingRect())
To copy to clipboard, switch view to plain text mode
And I call fitInView:
self.fitInView(self.scene().sceneRect(), Qt.KeepAspectRatio)
self.fitInView(self.scene().sceneRect(), Qt.KeepAspectRatio)
To copy to clipboard, switch view to plain text mode
But the view does not show the sceneRect completely but partially. (fig1.png). You can see the sceneRect drawn around the items. When I move all the items again in a different way, still the problem persists. (fig2.png)
It seemed like QGrapihcsView could not fit when we move the items out of the boundaries. So I tried to write a minimal example. I produced 10 random ellipses, fit the view and moved them and fit them. In some cases, view could not fit the whole image. (rect.py is the example code, try running multiple times as it is random)
Bookmarks