I\'ve been pulling my hair out with this one for hours. There\'s a thread here about it, but nothing seems to be working. QGraphicsView::rect() will return the width and hei
The following implementation returned the best results for me:
QRectF getVisibleRect( QGraphicsView * view )
{
QPointF A = view->mapToScene( QPoint(0, 0) );
QPointF B = view->mapToScene( QPoint(
view->viewport()->width(),
view->viewport()->height() ));
return QRectF( A, B );
}
This works still really well when scrollbars appear. This only works properly if the view does not display the scene rotated or sheared. If the view is rotated or sheared, then the visible rectangle is not axis parallel in the scene coordinate system. In this case
view->mapToScene( view->viewport()->geometry() )
returns a QPolygonF (NOT a QRectF) which is the visible rectangle in scene coordinates. By the way, QPolygonF has a member function boundingRect() which does not return the properly visible rectangle of the view, but might be useful anyways.