Important: Please read the Qt Code of Conduct -

QGraphicsView: How to calculate the center?

  • Hi,
    I am looking for the best way to calculate the current center of a QGraphicsView instance. The way to set the center is very easy using the centerOn() method, but if I want to get the opposite action (to get the QPoint center value), how should I do it?

    Thank you for any hint :)

  • Moderators

    QRectF rect = view->scene()->sceneRect();
    QPointF center =;

    or do you mean the center on which the scene is currently scrolled?

    QPointF sceneCenter = view->mapToScene( view->viewport()->rect().center() );

Log in to reply