Tom
Tom

Reputation: 4087

QGraphicsView and QGraphicsScene coordinate systems

in Qt 4.8 i have create a QGraphicsView and a DynamicRadarScene(derived from QGraphicsScene):

QGraphicsView* view = new QGraphicsView;
view->setMinimumSize(800, 600);
DynamicRadarScene* _scene = new DynamicRadarScene(mode, channel_types, this);
view->setScene(_scene);

What is the coordinate system of QGraphicsScene? (0,0) is from upper left corner? How can i draw an item in the upper right corner of the scene (i have set it 800x600: view->setMinimumSize(800, 600);)? If i resize the widget and so i resize the QGraphicsView, how can move the item i have drawn before to remain in the upper left corner?

Upvotes: 2

Views: 4153

Answers (2)

Marek R
Marek R

Reputation: 37512

QGraphicsScene has property sceneRect. If it is not set then it is auto adjusted depending on scene content. This can give a filling that origin of coordinating is in some strange place or even that it is mobile.

Set this property. See also this.

Upvotes: 1

TheDarkKnight
TheDarkKnight

Reputation: 27611

Yes, the upper left corner is generally the coordinate of (0,0) in a graphics scene. What you need to consider is that a QGraphicsView is like a window looking into a world (the QGraphicsScene). You set the view to look at an area or the scene, which may be all or just part of the scene.

Once the scene and view are setup, you can then add QGraphicsItems / QGraphicsObjects or instances of classes derived from those by using functions such as QGraphicsScene::addItem. These items are positioned in the scene and draw themselves.

i (sic) resize the widget and so i resize the QGraphicsView

You can change the QGraphicsView position and dimensions, but then the items in the scene will remain in the same place within the scene. Usually you would set up the scene and view and then move / resize the graphics items / objects within the scene, often with the setPos function: QGraphicsItem::setPos(). This sets the position of the item, relative to its parent. If the item has no parent, it sets the position of the item in the scene.

Upvotes: 1

Related Questions