Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt QGraphicsScene origin point

Tags:

c++

qt

Whenever I add a new item to a QGraphicsScene, the origin of the QGraphicsScene seem to change for the position of the item I have just added.

How to make the QGraphicsScene origin fixed?

Do I need to add the item first in the QGraphicsScene and then specify a position for the item?

like image 561
Chedy2149 Avatar asked Jan 01 '13 18:01

Chedy2149


2 Answers

Well, by default the content of the scene will be centered in the QGraphicsView. The origin of the graphics scene does not change randomly.

You might want to use setSceneRect() to define the size of the scene, so that the QGraphicsView always centers the scene in the view in a fixed manner. (If you don't set it manually, the rect will be calculated based on the items in the scene, which changes if you add more.)

like image 190
BastiBen Avatar answered Nov 15 '22 02:11

BastiBen


I answered a related question about a year ago that may be helpful:

How to draw a point (on mouseclick) on a QGraphicsScene?

Ditto to what badcat.

There are a lot of controls for adjusting or manipulating your viewport(s) that you have pointing at your scene. The scene sets what is on the stage. The view is how you look at it. Be sure to set the sceneRect or set it indirectly using centerOn or fitInView or scale or translate from the QGraphicsView class.

http://qt-project.org/doc/qt-4.8/graphicsview.html

http://qt-project.org/doc/qt-4.8/qgraphicsview.html

like image 3
phyatt Avatar answered Nov 15 '22 00:11

phyatt