3
votes

Greetings,

I'm trying to add a QGraphicsItem exactly in the center of the current 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 rectangle 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...

Thank you very much.

1

1 Answers

6
votes

You should map your top left corner (0,0) of your viewport to the scene. Width & height are equal to the viewport's rect width & height.

To get the rectangle of the current screen try this,:

QRect exposedRect(graphicsView.mapToScene(0,0).toPoint(), graphicsView.viewport()->rect().size());

I assume you can handle it from here.