PDA

View Full Version : Problem with QGraphicsView adjusting it's view



pstudio
31st January 2010, 01:45
Hey,

I've just started looking into Qt 4.6.1 (and I'm liking it :)) and I want to create a little vector graphics based program as an exercise.

I've subclassed QGraphicsScene so when you press left mouse button, it simply adds a QGraphicsPolygonItem. When such an item is added to the scene, the associated QGraphicsView automatically adjusts its view, so that all the items are centered. This may be a neat feature in some cases, but in this case it's just confusing, if the view always adjust itself when adding new items.

I've tried looking in the documentation and on the Diagram Scene example that comes with Qt Creator, but I can't find out how to prevent the QGraphicsView from automatically adjusting its view.

Any help would be appreciated.

Btw. I used Qt designer to create the form with QGraphicsView if that makes a difference.

wysota
31st January 2010, 02:21
When you don't explicitly set the size of the scene, it grows according to range of coordinates occupied by its items. At the same time if the view is larger than the scene then by default the scene is centred in the view. Toghether this causes the effect you are experiencing. If you want to avoid it, it's best if you set the geometry of the scene before adding items to it.

pstudio
31st January 2010, 02:53
Thanks, that solved the problem. I just knew it would be something simple like that :)