I'm using PyQt4 and trying to add a QGraphicsItem exactly in the center of the current screen, by clicking a menu button. So each click will add an item in the center of my screen.
My QGraphicsScene is very large (10k X 10K), so the QGraphicsView cannot show it entirely, there are scroll bars.

I can't find any function to return me the center point of my current screen, i searched in all QGraphicsScene and QGraphicsView functions.

There are functions to return the scene rect (it returns a rect 10k X 10k but it's useless) and there are functions to return the mouse position, but i need to move my mouse and click on a menu so the mouse will no longer be inside the scene and the item will be generated outside the visible space. And i also tried something with graphicsView.viewport().rect().center(), but it doesn't put my item in the center of the screen.

Thank you very much !

6 Years
Discussion Span
Last Post by Prahaai

If anyone is interested in the answer, that's it :

graphicsView.mapToScene( graphicsView.viewport()->rect().center() )

This returns the central point of current "screen".

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.