PDA

View Full Version : Moving QGraphicsItems and Fitting QGraphicsView



aladagemre
30th January 2010, 19:21
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().itemsBoundi ngRect())

And I call fitInView:

self.fitInView(self.scene().sceneRect(), Qt.KeepAspectRatio)

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)