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 !

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

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

This returns the central point of current "screen".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.