Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Visible Rect of a QGraphicsView
Adam Crowe last edited by Adam Crowe
Can someone recommend a method of finding the rect of the currently visible are of a QGraphicsView. Say the scene is larger than the view, how can I know what the visible area of the view is?
I'd like to use this to implement auto-scrolling while moving/dragging an item and also for a highlighted rectangle over a small overview view.
I've been Googling this quite a lot and found some suggestions. The main one is:
QPointF viewTopLeft = view->mapToScene(view->viewport()->x(), view->viewport()->y()); QPointF viewBottomRight = view->mapToScene(view->viewport()->width(), view->viewport()->height()); QRectF visibleRect = QRectF(viewTopLeft, viewBottomRight);
But this seems to return the same result every time regardless of the view. The result is the most top left corner.
I'm sure there is a straightforward solution that I'm missing.
Thank you in advance!
Did you check this stack overflow thread ?