سؤال

If I set a pixmap to a QGraphicsScene that is larger that the window, it will add scrollbars, So is it possible to get what is displayed in the QGraphicsView ?

Also Is there any event raised while scrolling and changeing the displayed area ?

Here is a screen of what I'm talking about: enter image description here

Thanks

هل كانت مفيدة؟

المحلول

You can determine visible area in the scene coordinates as follows:

QRect viewport_rect(0, 0, view->viewport()->width(), view->viewport()->height());
QRectF visible_scene_rect = view->mapToScene(viewport_rect).boundingRect();

You can use QGraphicsItem::mapFromScene to convert scene coordinates to item coordinates is necessary.

You can use view->horizontalScrollBar() and view->verticalScrollBar() to obtain QScrollBar* objects. Connect to valueChanged(int) signal of these objects to track scrolling.

نصائح أخرى

Also, note the viewport contains a function to fit an area of the scene into the view so that you can see all of that area using: -

void QGraphicsView::fitInView(const QRectF & rect, Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top