开发者

Qt add item in the center of the scene/ view

开发者 https://www.devze.com 2023-03-04 18:55 出处:网络
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

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号