Search code examples
qtcoordinate-systemsqgraphicsscene

Meaning of first two parameters of QGraphicsScene constructor


I can construct a QGraphicsScene by using constructor below:

QGraphicsScene::QGraphicsScene ( qreal x, qreal y, qreal width, qreal height, QObject * parent = 0 )

For example:

QGraphicsScene scene(-350, -350, 700, 700);

I know the first two parameters represent a point, but in which coordinate system?

When I create a QGraphics object and show this view like this:

QGraphicsView view(&scene);
view.show();

Where will this view appear on my device? Is the location controlled by first two parameters mentioned above?


Solution

  • The first two parameter mean, when a view focus on this scene, which point in the scene is the top-left corner of the view.

    In your code, the -350,-350 will be the top-left corner of the view window.

    Here's another example:

    QGraphicsScene *scene = new QGraphicsScene;
    scene->setSceneRect(-360,-240,720,480);
    QGraphicsView *view  = new QGraphicsView(this);
    view->setScene(scene);
    

    if you try to add item without telling where to show it, it will show at (0,0). And in the code above, is the center of the view.