Search code examples
qgraphicsview

How do I make the top left of a QGraphicsScene coincide with the top left of my QGraphicsView?


I always have trouble with the QGraphicsScene coordinate system. My scene is created quite simply like so:

scene = new QGraphicsScene(this);
this->setScene(scene);

where this is QGraphicsView. Now I want to draw a rectangle at (0,0) This creates rectangle that is roughly in the middle of the screen. How do I make it so that (0,0) corresponds to the upper left corner of my view? This is so I know where I can position anything...


Solution

  • Yo can try this method: QGraphicsView::setAlignment(Qt::Alignment alignment) (see here)

    You would have to use something like:

    scene->setAlignment(Qt::AlignTop|Qt::AlignLeft);