Dmitrii Volosnykh
Dmitrii Volosnykh

Reputation: 1185

How to get visible scene rect for QGraphicsView

Imagine QGraphicsView is set with the scene that is twice as wider as view's width. sceneRect() will return the whole scene rect. I'd like to get the rect representing the half of the scene with respect to scrollbars' positions.

Upvotes: 1

Views: 1248

Answers (2)

Tomas
Tomas

Reputation: 2210

Get the viewport rectangle with the graphicsView->viewport()->rect() and map it to the scene space with the graphicsView->mapToScene().

Upvotes: 1

Silicomancer
Silicomancer

Reputation: 9156

I am not totally sure which rectangle you exactly need (this depends from what you want to do) but something like graphicsView->viewport()->contentsRect() or graphicsView->viewport()->geometry() should work.

Upvotes: 0

Related Questions