com.trolltech.qt.gui
Class QGraphicsView

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.core.QObject
              extended by com.trolltech.qt.gui.QWidget
                  extended by com.trolltech.qt.gui.QFrame
                      extended by com.trolltech.qt.gui.QAbstractScrollArea
                          extended by com.trolltech.qt.gui.QGraphicsView
All Implemented Interfaces:
QPaintDeviceInterface, QtJambiInterface

public class QGraphicsView
extends QAbstractScrollArea

The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.

QGraphicsView visualizes the contents of a QGraphicsScene in a scrollable viewport. To create a scene with geometrical items, see QGraphicsScene's documentation. QGraphicsView is part of The Graphics View Framework.

To visualize a scene, you start by constructing a QGraphicsView object, passing the address of the scene you want to visualize to QGraphicsView's constructor. Alternatively, you can call setScene to set the scene at a later point. After you call show, the view will by default scroll to the center of the scene and display any items that are visible at this point. For example:

    QGraphicsScene scene;
    scene.addText("Hello, world!");

    QGraphicsView view(&scene);
    view.show();

You can explicitly scroll to any position on the scene by using the scroll bars, or by calling centerOn. By passing a point to centerOn, QGraphicsView will scroll its viewport to ensure that the point is centered in the view. An overload is provided for scrolling to a QGraphicsItem, in which case QGraphicsView will see to that the center of the item is centered in the view. If all you want is to ensure that a certain area is visible, (but not necessarily centered,) you can call ensureVisible instead.

QGraphicsView can be used to visualize a whole scene, or only parts of it. The visualized area is by default detected automatically when the view is displayed for the first time (by calling QGraphicsScene::itemsBoundingRect()). To set the visualized area rectangle yourself, you can call setSceneRect. This will adjust the scroll bars' ranges appropriately. Note that although the scene supports a virtually unlimited size, the range of the scroll bars will never exceed the range of an integer (INT_MIN, INT_MAX). When the scene is larger than the scroll bars' values, you can choose to use translate to navigate the scene instead.

QGraphicsView visualizes the scene by calling render. By default, the items are drawn onto the viewport by using a regular QPainter, and using default render hints. To change the default render hints that QGraphicsView passes to QPainter when painting items, you can call setRenderHints.

By default, QGraphicsView provides a regular QWidget for the viewport widget. You can access this widget by calling viewport, or you can replace it by calling setViewport. To render using OpenGL, simply call setViewport(new QGLWidget). QGraphicsView takes ownership of the viewport widget.

QGraphicsView supports affine transformations, using QMatrix. You can either pass a matrix to setMatrix, or you can call one of the convenience functions rotate, scale, translate or shear. The most two common transformations are scaling, which is used to implement zooming, and rotation. QGraphicsView keeps the center of the view fixed during a transformation.

You can interact with the items on the scene by using the mouse and keyboard. QGraphicsView translates the mouse and key events into scene events, (events that inherit QGraphicsSceneEvent,), and forward them to the visualized scene. In the end, it's the individual item that handles the events and reacts to them. For example, if you click on a selectable item, the item will typically let the scene know that it has been selected, and it will also redraw itself to display a selection rectangle. Similiary, if you click and drag the mouse to move a movable item, it's the item that handles the mouse moves and moves itself. Item interaction is enabled by default, and you can toggle it by calling setInteractive.

You can also provide your own custom scene interaction, by creating a subclass of QGraphicsView, and reimplementing the mouse and key event handlers. To simplify how you programmatically interact with items in the view, QGraphicsView provides the mapping functions mapToScene and mapFromScene, and the item accessors items and itemAt. These functions allow you to map points, rectangles, polygons and paths between view coordinates and scene coordinates, and to find items on the scene using view coordinates.

See Also:
QGraphicsScene, QGraphicsItem, QGraphicsSceneEvent

Nested Class Summary
static class QGraphicsView.CacheMode
          This QFlag class provides flags for the int enum.
static class QGraphicsView.CacheModeFlag
          This enum describes the flags that you can set for a QGraphicsView's cache mode.
static class QGraphicsView.DragMode
          This enum describes the default action for the view when pressing and dragging the mouse over the viewport.
static class QGraphicsView.OptimizationFlag
          This enum describes flags that you can enable to improve rendering performance in QGraphicsView.
static class QGraphicsView.OptimizationFlags
          This QFlag class provides flags for the int enum.
static class QGraphicsView.ViewportAnchor
          This enums describe the possible anchors that QGraphicsView can use when the user resizes the view or when the view is transformed.
static class QGraphicsView.ViewportUpdateMode
          This enum describes how QGraphicsView updates its viewport when the scene contents change or are exposed.
 
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QFrame
QFrame.Shadow, QFrame.Shape, QFrame.StyleMask
 
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QWidget
QWidget.RenderFlag, QWidget.RenderFlags
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
Field Summary
 
Fields inherited from class com.trolltech.qt.gui.QWidget
customContextMenuRequested
 
Constructor Summary
QGraphicsView()
          Equivalent to QGraphicsView(0).
QGraphicsView(QGraphicsScene scene)
          Equivalent to QGraphicsView(scene, 0).
QGraphicsView(QGraphicsScene scene, QWidget parent)
          Constructs a QGraphicsView and sets the visualized scene to scene.
QGraphicsView(QWidget parent)
          Constructs a QGraphicsView.
 
Method Summary
 Qt.Alignment alignment()
          Returns the alignment of the scene in the view when the whole scene is visible..
 QBrush backgroundBrush()
          Returns the background brush of the scene..
 QGraphicsView.CacheMode cacheMode()
          Returns which parts of the view are cached.
 void centerOn(double x, double y)
          This function is provided for convenience.
 void centerOn(QGraphicsItemInterface item)
          Scrolls the contents of the viewport to ensure that item is centered in the view.
 void centerOn(QPointF pos)
          Scrolls the contents of the viewport to ensure that the scene coordinate pos, is centered in the view.
protected  void contextMenuEvent(QContextMenuEvent event)
          This function is reimplemented for internal reasons.
protected  void dragEnterEvent(QDragEnterEvent event)
          This function is reimplemented for internal reasons.
protected  void dragLeaveEvent(QDragLeaveEvent event)
          This function is reimplemented for internal reasons.
 QGraphicsView.DragMode dragMode()
          Returns the behavior for dragging the mouse over the scene while the left mouse button is pressed..
protected  void dragMoveEvent(QDragMoveEvent event)
          This function is reimplemented for internal reasons.
protected  void drawBackground(QPainter painter, QRectF rect)
          Draws the background of the scene using painter, before any items and the foreground are drawn.
protected  void drawForeground(QPainter painter, QRectF rect)
          Draws the foreground of the scene using painter, after the background and all items are drawn.
protected  void drawItems(QPainter painter, QGraphicsItemInterface[] items, QStyleOptionGraphicsItem[] options)
          Equivalent to drawItems(painter, items, options, ).
protected  void dropEvent(QDropEvent event)
          This function is reimplemented for internal reasons.
 void ensureVisible(double x, double y, double w, double h)
          Equivalent to ensureVisible(x, y, w, h, 50, 50).
 void ensureVisible(double x, double y, double w, double h, int xmargin)
          Equivalent to ensureVisible(x, y, w, h, xmargin, 50).
 void ensureVisible(double x, double y, double w, double h, int xmargin, int ymargin)
          This function is provided for convenience.
 void ensureVisible(QGraphicsItemInterface item)
          Equivalent to ensureVisible(item, 50, 50).
 void ensureVisible(QGraphicsItemInterface item, int xmargin)
          Equivalent to ensureVisible(item, xmargin, 50).
 void ensureVisible(QGraphicsItemInterface item, int xmargin, int ymargin)
          Scrolls the contents of the viewport so that the center of item item is visible, with margins specified in pixels by xmargin and ymargin.
 void ensureVisible(QRectF rect)
          Equivalent to ensureVisible(rect, 50, 50).
 void ensureVisible(QRectF rect, int xmargin)
          Equivalent to ensureVisible(rect, xmargin, 50).
 void ensureVisible(QRectF rect, int xmargin, int ymargin)
          Scrolls the contents of the viewport so that the scene rectangle rect is visible, with margins specified in pixels by xmargin and ymargin.
 boolean event(QEvent event)
          This function is reimplemented for internal reasons.
 void fitInView(double x, double y, double w, double h)
          Equivalent to fitInView(x, y, w, h, Qt::IgnoreAspectRatio).
 void fitInView(double x, double y, double w, double h, Qt.AspectRatioMode aspectRadioMode)
          This convenience function is equivalent to calling fitInView(QRectF(x, y, w, h), aspectRadioMode).
 void fitInView(QGraphicsItemInterface item)
          Equivalent to fitInView(item, Qt::IgnoreAspectRatio).
 void fitInView(QGraphicsItemInterface item, Qt.AspectRatioMode aspectRadioMode)
          Ensures that item fits tightly inside the view, scaling the view according to aspectRadioMode.
 void fitInView(QRectF rect)
          Equivalent to fitInView(rect, Qt::IgnoreAspectRatio).
 void fitInView(QRectF rect, Qt.AspectRatioMode aspectRadioMode)
          Scales the view matrix and scrolls the scroll bars to ensure that the scene rectangle rect fits inside the viewport.
protected  void focusInEvent(QFocusEvent event)
          This function is reimplemented for internal reasons.
protected  void focusOutEvent(QFocusEvent event)
          This function is reimplemented for internal reasons.
 QBrush foregroundBrush()
          Returns the foreground brush of the scene..
static QGraphicsView fromNativePointer(QNativePointer nativePointer)
          This function returns the QGraphicsView instance pointed to by nativePointer
protected  void inputMethodEvent(QInputMethodEvent event)
          This function is reimplemented for internal reasons.
 java.lang.Object inputMethodQuery(Qt.InputMethodQuery query)
          This function is reimplemented for internal reasons.
 void invalidateScene()
          Equivalent to invalidateScene(QRectF(), QGraphicsScene::AllLayers).
 void invalidateScene(QRectF rect)
          Equivalent to invalidateScene(rect, QGraphicsScene::AllLayers).
 void invalidateScene(QRectF rect, QGraphicsScene.SceneLayer... layers)
          Invalidates and schedules a redraw of layers inside rect.
 void invalidateScene(QRectF rect, QGraphicsScene.SceneLayers layers)
          Invalidates and schedules a redraw of layers inside rect.
 boolean isInteractive()
          Returns whether the view allowed scene interaction..
 QGraphicsItemInterface itemAt(int x, int y)
          This function is provided for convenience.
 QGraphicsItemInterface itemAt(QPoint pos)
          Returns the item at position pos, which is in viewport coordinates.
 java.util.List<QGraphicsItemInterface> items()
          Returns a list of all the items in the associated scene.
 java.util.List<QGraphicsItemInterface> items(int x, int y)
          This function is provided for convenience.
 java.util.List<QGraphicsItemInterface> items(int x, int y, int w, int h)
          This convenience function is equivalent to calling items(QRectF(x, y, w, h)).
 java.util.List<QGraphicsItemInterface> items(int x, int y, int w, int h, Qt.ItemSelectionMode mode)
          This convenience function is equivalent to calling items(QRectF(x, y, w, h), mode).
 java.util.List<QGraphicsItemInterface> items(QPainterPath path)
          Returns a list of all the items that are either contained by or intersect with path.
 java.util.List<QGraphicsItemInterface> items(QPainterPath path, Qt.ItemSelectionMode mode)
          Returns a list of all the items that, depending on mode, are either contained by or intersect with path.
 java.util.List<QGraphicsItemInterface> items(QPoint pos)
          Returns a list of all the items at the position pos in the view.
 java.util.List<QGraphicsItemInterface> items(QPolygon polygon)
          Returns a list of all the items that are either contained by or intersect with polygon.
 java.util.List<QGraphicsItemInterface> items(QPolygon polygon, Qt.ItemSelectionMode mode)
          Returns a list of all the items that, depending on mode, are either contained by or intersect with polygon.
 java.util.List<QGraphicsItemInterface> items(QRect rect)
          Returns a list of all the items that are either contained by or intersect with rect.
 java.util.List<QGraphicsItemInterface> items(QRect rect, Qt.ItemSelectionMode mode)
          Returns a list of all the items that, depending on mode, are either contained by or intersect with rect.
protected  void keyPressEvent(QKeyEvent event)
          This function is reimplemented for internal reasons.
protected  void keyReleaseEvent(QKeyEvent event)
          This function is reimplemented for internal reasons.
 QPoint mapFromScene(double x, double y)
          This function is provided for convenience.
 QPolygon mapFromScene(double x, double y, double w, double h)
          This function is provided for convenience.
 QPainterPath mapFromScene(QPainterPath path)
          Returns the scene coordinate painter path path to a viewport coordinate painter path.
 QPoint mapFromScene(QPointF point)
          Returns the scene coordinate point to viewport coordinates.
 QPolygon mapFromScene(QPolygonF polygon)
          Returns the scene coordinate polygon polygon to a viewport coordinate polygon.
 QPolygon mapFromScene(QRectF rect)
          Returns the scene rectangle rect to a viewport coordinate polygon.
 QPointF mapToScene(int x, int y)
          This function is provided for convenience.
 QPolygonF mapToScene(int x, int y, int w, int h)
          This function is provided for convenience.
 QPainterPath mapToScene(QPainterPath path)
          Returns the viewport painter path path mapped to a scene coordinate painter path.
 QPointF mapToScene(QPoint point)
          Returns the viewport coordinate point mapped to scene coordinates.
 QPolygonF mapToScene(QPolygon polygon)
          Returns the viewport polygon polygon mapped to a scene coordinate polygon.
 QPolygonF mapToScene(QRect rect)
          Returns the viewport rectangle rect mapped to a scene coordinate polygon.
 QMatrix matrix()
          Returns the current transformation matrix for the view.
protected  void mouseDoubleClickEvent(QMouseEvent event)
          This function is reimplemented for internal reasons.
protected  void mouseMoveEvent(QMouseEvent event)
          This function is reimplemented for internal reasons.
protected  void mousePressEvent(QMouseEvent event)
          This function is reimplemented for internal reasons.
protected  void mouseReleaseEvent(QMouseEvent event)
          This function is reimplemented for internal reasons.
 QGraphicsView.OptimizationFlags optimizationFlags()
          Returns flags that can be used to tune QGraphicsView's performance..
protected  void paintEvent(QPaintEvent event)
          This function is reimplemented for internal reasons.
 void render(QPainter painter)
          Equivalent to render(painter, QRectF(), QRect(), Qt::KeepAspectRatio).
 void render(QPainter painter, QRectF target)
          Equivalent to render(painter, target, QRect(), Qt::KeepAspectRatio).
 void render(QPainter painter, QRectF target, QRect source)
          Equivalent to render(painter, target, source, Qt::KeepAspectRatio).
 void render(QPainter painter, QRectF target, QRect source, Qt.AspectRatioMode aspectRatioMode)
          Renders the source rect, which is in view coordinates, from the scene into target, which is in paint device coordinates, using painter.
 QPainter.RenderHints renderHints()
          Returns the default render hints for the view.
 void resetCachedContent()
          Resets any cached content.
 void resetMatrix()
          Resets the view transformation matrix to the identity matrix.
 void resetTransform()
          Resets the view transformation to the identity matrix.
 QGraphicsView.ViewportAnchor resizeAnchor()
          Returns how the view should position the scene when the view is resized..
protected  void resizeEvent(QResizeEvent event)
          This function is reimplemented for internal reasons.
 void rotate(double angle)
          Rotates the current view transformation angle degrees clockwise.
 Qt.ItemSelectionMode rubberBandSelectionMode()
          Returns the behavior for selecting items with a rubber band selection rectangle..
 void scale(double sx, double sy)
          Scales the current view transformation by (sx, sy).
 QGraphicsScene scene()
          Returns a pointer to the scene that is currently visualized in the view.
 QRectF sceneRect()
          Returns the area of the scene visualized by this view..
protected  void scrollContentsBy(int dx, int dy)
          This function is reimplemented for internal reasons.
 void setAlignment(Qt.Alignment alignment)
          Sets the alignment of the scene in the view when the whole scene is visible.
 void setAlignment(Qt.AlignmentFlag... alignment)
          Sets the alignment of the scene in the view when the whole scene is visible.
 void setBackgroundBrush(QBrush brush)
          Sets the background brush of the scene.
 void setCacheMode(QGraphicsView.CacheMode mode)
          Sets which parts of the view are cached to mode.
 void setCacheMode(QGraphicsView.CacheModeFlag... mode)
          Sets which parts of the view are cached to mode.
 void setDragMode(QGraphicsView.DragMode mode)
          Sets the behavior for dragging the mouse over the scene while the left mouse button is pressed.
 void setForegroundBrush(QBrush brush)
          Sets the foreground brush of the scene.
 void setInteractive(boolean allowed)
          Sets whether the view allowed scene interaction.
 void setMatrix(QMatrix matrix)
          Equivalent to setMatrix(matrix, false).
 void setMatrix(QMatrix matrix, boolean combine)
          Sets the view's current transformation matrix to matrix.
 void setOptimizationFlag(QGraphicsView.OptimizationFlag flag)
          Equivalent to setOptimizationFlag(flag, true).
 void setOptimizationFlag(QGraphicsView.OptimizationFlag flag, boolean enabled)
          Enables flag if enabled is true; otherwise disables flag.
 void setOptimizationFlags(QGraphicsView.OptimizationFlag... flags)
          Sets flags that can be used to tune QGraphicsView's performance.
 void setOptimizationFlags(QGraphicsView.OptimizationFlags flags)
          Sets flags that can be used to tune QGraphicsView's performance.
 void setRenderHint(QPainter.RenderHint hint)
          Equivalent to setRenderHint(hint, true).
 void setRenderHint(QPainter.RenderHint hint, boolean enabled)
          If enabled is true, the render hint hint is enabled; otherwise it is disabled.
 void setRenderHints(QPainter.RenderHint... hints)
          Sets the default render hints for the view to hints.
 void setRenderHints(QPainter.RenderHints hints)
          Sets the default render hints for the view to hints.
 void setResizeAnchor(QGraphicsView.ViewportAnchor anchor)
          Sets how the view should position the scene when the view is resized.
 void setRubberBandSelectionMode(Qt.ItemSelectionMode mode)
          Sets the behavior for selecting items with a rubber band selection rectangle.
 void setScene(QGraphicsScene scene)
          Sets the current scene to scene.
 void setSceneRect(double x, double y, double w, double h)
          Sets the area of the scene visualized by this view..
 void setSceneRect(QRectF rect)
          Sets the area of the scene visualized by this view.
 void setTransform(QTransform matrix)
          Equivalent to setTransform(matrix, false).
 void setTransform(QTransform matrix, boolean combine)
          Sets the view's current transformation matrix to matrix.
 void setTransformationAnchor(QGraphicsView.ViewportAnchor anchor)
          Sets how the view should position the scene during transformations.
protected  void setupViewport(QWidget widget)
          This slot is called by QAbstractScrollArea after setViewport has been called.
 void setViewportUpdateMode(QGraphicsView.ViewportUpdateMode mode)
          Sets how the viewport should update its contents.
 void shear(double sh, double sv)
          Shears the current view transformation by (sh, sv).
protected  void showEvent(QShowEvent event)
          This function is reimplemented for internal reasons.
 QSize sizeHint()
          This function is reimplemented for internal reasons.
 QTransform transform()
          Returns the current transformation matrix for the view.
 QGraphicsView.ViewportAnchor transformationAnchor()
          Returns how the view should position the scene during transformations..
 void translate(double dx, double dy)
          Translates the current view transformation by (dx, dy).
 void updateScene(java.util.List<QRectF> rects)
          Schedules an update of the scene rectangles rects.
 void updateSceneRect(QRectF rect)
          Notifies QGraphicsView that the scene's scene rect has changed.
protected  boolean viewportEvent(QEvent event)
          This function is reimplemented for internal reasons.
 QTransform viewportTransform()
          Returns a matrix that maps viewport coordinates to scene coordinates.
 QGraphicsView.ViewportUpdateMode viewportUpdateMode()
          Returns how the viewport should update its contents..
protected  void wheelEvent(QWheelEvent event)
          This function is reimplemented for internal reasons.
 
Methods inherited from class com.trolltech.qt.gui.QAbstractScrollArea
addScrollBarWidget, addScrollBarWidget, cornerWidget, horizontalScrollBar, horizontalScrollBarPolicy, maximumViewportSize, minimumSizeHint, paintEngine, scrollBarWidgets, scrollBarWidgets, setCornerWidget, setHorizontalScrollBar, setHorizontalScrollBarPolicy, setVerticalScrollBar, setVerticalScrollBarPolicy, setViewport, setViewportMargins, verticalScrollBar, verticalScrollBarPolicy, viewport
 
Methods inherited from class com.trolltech.qt.gui.QFrame
changeEvent, drawFrame, frameRect, frameShadow, frameShape, frameStyle, frameWidth, lineWidth, midLineWidth, setFrameRect, setFrameShadow, setFrameShape, setFrameStyle, setLineWidth, setMidLineWidth
 
Methods inherited from class com.trolltech.qt.gui.QWidget
acceptDrops, accessibleDescription, accessibleName, actionEvent, actions, activateWindow, addAction, addActions, adjustSize, autoFillBackground, backgroundRole, baseSize, childAt, childAt, childrenRect, childrenRegion, clearFocus, clearMask, close, closeEvent, contentsRect, contextMenuPolicy, createWinId, cursor, depth, destroy, destroy, destroy, devType, ensurePolished, enterEvent, focusNextChild, focusNextPrevChild, focusPolicy, focusPreviousChild, focusProxy, focusWidget, font, fontInfo, fontMetrics, foregroundRole, frameGeometry, frameSize, geometry, getContentsMargins, grabKeyboard, grabMouse, grabMouse, grabShortcut, grabShortcut, hasFocus, hasMouseTracking, height, heightForWidth, heightMM, hide, hideEvent, inputContext, insertAction, insertActions, isActiveWindow, isAncestorOf, isEnabled, isEnabledTo, isFullScreen, isHidden, isLeftToRight, isMaximized, isMinimized, isModal, isRightToLeft, isVisible, isVisibleTo, isWindow, isWindowModified, keyboardGrabber, layout, layoutDirection, leaveEvent, locale, logicalDpiX, logicalDpiY, lower, mapFrom, mapFromGlobal, mapFromParent, mapTo, mapToGlobal, mapToParent, mask, maximumHeight, maximumSize, maximumWidth, metric, minimumHeight, minimumSize, minimumWidth, mouseGrabber, move, move, moveEvent, nextInFocusChain, normalGeometry, numColors, overrideWindowFlags, overrideWindowFlags, overrideWindowState, overrideWindowState, paintingActive, palette, parentWidget, physicalDpiX, physicalDpiY, pos, raise, rect, releaseKeyboard, releaseMouse, releaseShortcut, removeAction, render, render, render, render, render, repaint, repaint, repaint, repaint, resetInputContext, resize, resize, restoreGeometry, saveGeometry, scroll, scroll, setAcceptDrops, setAccessibleDescription, setAccessibleName, setAttribute, setAttribute, setAutoFillBackground, setBackgroundRole, setBaseSize, setBaseSize, setContentsMargins, setContentsMargins, setContextMenuPolicy, setCursor, setDisabled, setEnabled, setFixedHeight, setFixedSize, setFixedSize, setFixedWidth, setFocus, setFocus, setFocusPolicy, setFocusProxy, setFont, setForegroundRole, setGeometry, setGeometry, setHidden, setInputContext, setLayout, setLayoutDirection, setLocale, setMask, setMask, setMaximumHeight, setMaximumSize, setMaximumSize, setMaximumWidth, setMinimumHeight, setMinimumSize, setMinimumSize, setMinimumWidth, setMouseTracking, setPalette, setParent, setParent, setParent, setShortcutAutoRepeat, setShortcutAutoRepeat, setShortcutEnabled, setShortcutEnabled, setSizeIncrement, setSizeIncrement, setSizePolicy, setSizePolicy, setStatusTip, setStyle, setStyleSheet, setTabOrder, setToolTip, setUpdatesEnabled, setVisible, setWhatsThis, setWindowFlags, setWindowFlags, setWindowIcon, setWindowIconText, setWindowModality, setWindowModified, setWindowOpacity, setWindowRole, setWindowState, setWindowState, setWindowTitle, show, showFullScreen, showMaximized, showMinimized, showNormal, size, sizeIncrement, sizePolicy, stackUnder, statusTip, style, styleSheet, tabletEvent, testAttribute, toolTip, underMouse, unsetCursor, unsetLayoutDirection, unsetLocale, update, update, update, update, updateGeometry, updateMicroFocus, updatesEnabled, visibleRegion, whatsThis, width, widthMM, window, windowFlags, windowIcon, windowIconText, windowModality, windowOpacity, windowRole, windowState, windowTitle, windowType, winId, x, y
 
Methods inherited from class com.trolltech.qt.core.QObject
blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, timerEvent
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
disconnect, disconnect, signalSender
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

QGraphicsView

public QGraphicsView()

Equivalent to QGraphicsView(0).


QGraphicsView

public QGraphicsView(QWidget parent)

Constructs a QGraphicsView. parent is passed to QWidget's constructor.


QGraphicsView

public QGraphicsView(QGraphicsScene scene)

Equivalent to QGraphicsView(scene, 0).


QGraphicsView

public QGraphicsView(QGraphicsScene scene,
                     QWidget parent)

Constructs a QGraphicsView and sets the visualized scene to scene. parent is passed to QWidget's constructor.

Method Detail

alignment

public final Qt.Alignment alignment()

Returns the alignment of the scene in the view when the whole scene is visible..

If the whole scene is visible in the view, (i.e., there are no visible scroll bars,) the view's alignment will decide where the scene will be rendered in the view. For example, if the alignment is Qt::AlignCenter, which is default, the scene will be centered in the view, and if the alignment is (Qt::AlignLeft | Qt::AlignTop), the scene will be rendered in the top-left corner of the view.

See Also:
setAlignment

backgroundBrush

public final QBrush backgroundBrush()

Returns the background brush of the scene..

This property sets the background brush for the scene in this view. It is used to override the scene's own background, and defines the behavior of drawBackground. To provide custom background drawing for this view, you can reimplement drawBackground instead.

See Also:
setBackgroundBrush, QGraphicsScene::backgroundBrush, foregroundBrush

cacheMode

public final QGraphicsView.CacheMode cacheMode()

Returns which parts of the view are cached.

QGraphicsView can cache pre-rendered content in a QPixmap, which is then drawn onto the viewport. The purpose of such caching is to speed up the total rendering time for areas that are slow to render. Texture, gradient and alpha blended backgrounds, for example, can be notibly slow to render; especially with a transformed view. The CacheBackground flag enables caching of the view's background. For example:

    QGraphicsView view;
    view.setBackgroundBrush(":/images/backgroundtile.png");
    view.setCacheMode(QGraphicsView::CacheBackground);

The cache is invalidated every time the view is transformed. However, when scrolling, only partial invalidation is required.

By default, nothing is cached.

See Also:
setCacheMode, resetCachedContent, QPixmapCache

centerOn

public final void centerOn(double x,
                           double y)

This function is provided for convenience. It's equivalent to calling centerOn(QPointF(x, y)).


centerOn

public final void centerOn(QPointF pos)

Scrolls the contents of the viewport to ensure that the scene coordinate pos, is centered in the view.

Because pos is a floating point coordinate, and the scroll bars operate on integer coordinates, the centering is only an approximation.

See Also:
ensureVisible

centerOn

public final void centerOn(QGraphicsItemInterface item)

Scrolls the contents of the viewport to ensure that item is centered in the view.

See Also:
ensureVisible

dragMode

public final QGraphicsView.DragMode dragMode()

Returns the behavior for dragging the mouse over the scene while the left mouse button is pressed..

This property defines what should happen when the user clicks on the scene background and drags the mouse (e.g., scrolling the viewport contents using a pointing hand cursor, or selecting multiple items with a rubber band). The default value, NoDrag, does nothing.

This behavior only affects mouse clicks that are not handled by any item. You can define a custom behavior by creating a subclass of QGraphicsView and reimplementing mouseMoveEvent.

See Also:
setDragMode

ensureVisible

public final void ensureVisible(QGraphicsItemInterface item,
                                int xmargin)

Equivalent to ensureVisible(item, xmargin, 50).


ensureVisible

public final void ensureVisible(QGraphicsItemInterface item)

Equivalent to ensureVisible(item, 50, 50).


ensureVisible

public final void ensureVisible(QGraphicsItemInterface item,
                                int xmargin,
                                int ymargin)

Scrolls the contents of the viewport so that the center of item item is visible, with margins specified in pixels by xmargin and ymargin. If the specified point cannot be reached, the contents are scrolled to the nearest valid position. The default value for both margins is 50 pixels.

See Also:
centerOn

ensureVisible

public final void ensureVisible(QRectF rect,
                                int xmargin)

Equivalent to ensureVisible(rect, xmargin, 50).


ensureVisible

public final void ensureVisible(QRectF rect)

Equivalent to ensureVisible(rect, 50, 50).


ensureVisible

public final void ensureVisible(QRectF rect,
                                int xmargin,
                                int ymargin)

Scrolls the contents of the viewport so that the scene rectangle rect is visible, with margins specified in pixels by xmargin and ymargin. If the specified rect cannot be reached, the contents are scrolled to the nearest valid position. The default value for both margins is 50 pixels.

See Also:
centerOn

ensureVisible

public final void ensureVisible(double x,
                                double y,
                                double w,
                                double h,
                                int xmargin)

Equivalent to ensureVisible(x, y, w, h, xmargin, 50).


ensureVisible

public final void ensureVisible(double x,
                                double y,
                                double w,
                                double h)

Equivalent to ensureVisible(x, y, w, h, 50, 50).


ensureVisible

public final void ensureVisible(double x,
                                double y,
                                double w,
                                double h,
                                int xmargin,
                                int ymargin)

This function is provided for convenience. It's equivalent to calling ensureVisible(QRectF(x, y, w, h), xmargin, ymargin).


fitInView

public final void fitInView(QRectF rect)

Equivalent to fitInView(rect, Qt::IgnoreAspectRatio).


fitInView

public final void fitInView(QRectF rect,
                            Qt.AspectRatioMode aspectRadioMode)

Scales the view matrix and scrolls the scroll bars to ensure that the scene rectangle rect fits inside the viewport. rect must be inside the scene rect; otherwise, fitInView cannot guarantee that the whole rect is visible.

This function keeps the view's rotation, translation, or shear. The view is scaled according to aspectRadioMode. rect will be centered in the view if it does not fit tightly.

See Also:
setMatrix, ensureVisible, centerOn

fitInView

public final void fitInView(double x,
                            double y,
                            double w,
                            double h)

Equivalent to fitInView(x, y, w, h, Qt::IgnoreAspectRatio).


fitInView

public final void fitInView(double x,
                            double y,
                            double w,
                            double h,
                            Qt.AspectRatioMode aspectRadioMode)

This convenience function is equivalent to calling fitInView(QRectF(x, y, w, h), aspectRadioMode).

See Also:
ensureVisible, centerOn

fitInView

public final void fitInView(QGraphicsItemInterface item)

Equivalent to fitInView(item, Qt::IgnoreAspectRatio).


fitInView

public final void fitInView(QGraphicsItemInterface item,
                            Qt.AspectRatioMode aspectRadioMode)

Ensures that item fits tightly inside the view, scaling the view according to aspectRadioMode.

See Also:
ensureVisible, centerOn

foregroundBrush

public final QBrush foregroundBrush()

Returns the foreground brush of the scene..

This property sets the foreground brush for the scene in this view. It is used to override the scene's own foreground, and defines the behavior of drawForeground. To provide custom background drawing for this view, you can reimplement drawBackground instead.

See Also:
setForegroundBrush, QGraphicsScene::foregroundBrush, backgroundBrush

invalidateScene

public final void invalidateScene(QRectF rect,
                                  QGraphicsScene.SceneLayer... layers)

Invalidates and schedules a redraw of layers inside rect. rect is in scene coordinates. Any cached content for layers inside rect is unconditionally invalidated and redrawn.

You can call this function to notify QGraphicsView of changes to the background or the foreground of the scene. It is commonly used for scenes with tile-based backgrounds to notify changes when QGraphicsView has enabled background caching.

Note that QGraphicsView currently supports background caching only (see CachedBackground). This function is equivalent to calling update if any layer but QGraphicsScene::BackgroundLayer is passed.

See Also:
QGraphicsScene::invalidate, update

invalidateScene

public final void invalidateScene(QRectF rect)

Equivalent to invalidateScene(rect, QGraphicsScene::AllLayers).


invalidateScene

public final void invalidateScene()

Equivalent to invalidateScene(QRectF(), QGraphicsScene::AllLayers).


invalidateScene

public final void invalidateScene(QRectF rect,
                                  QGraphicsScene.SceneLayers layers)

Invalidates and schedules a redraw of layers inside rect. rect is in scene coordinates. Any cached content for layers inside rect is unconditionally invalidated and redrawn.

You can call this function to notify QGraphicsView of changes to the background or the foreground of the scene. It is commonly used for scenes with tile-based backgrounds to notify changes when QGraphicsView has enabled background caching.

Note that QGraphicsView currently supports background caching only (see CachedBackground). This function is equivalent to calling update if any layer but QGraphicsScene::BackgroundLayer is passed.

See Also:
QGraphicsScene::invalidate, update

isInteractive

public final boolean isInteractive()

Returns whether the view allowed scene interaction..

If enabled, this view is set to allow scene interaction. Otherwise, this view will not allow interaction, and any mouse or key events are ignored (i.e., it will act as a read-only view).


itemAt

public final QGraphicsItemInterface itemAt(int x,
                                           int y)

This function is provided for convenience. It's equivalent to calling itemAt(QPoint(x, y)).


itemAt

public final QGraphicsItemInterface itemAt(QPoint pos)

Returns the item at position pos, which is in viewport coordinates. If there are several items at this position, this function returns the topmost item.

Example:

    void CustomView::mousePressEvent(QMouseEvent *event)
    {
        if (QGraphicsItem *item = itemAt(event->pos())) {
            qDebug() << "You clicked on item" << item;
        } else {
            qDebug() << "You didn't click on an item.";
        }
    }

See Also:
items

items

public final java.util.List<QGraphicsItemInterface> items(QRect rect)
Returns a list of all the items that are either contained by or intersect with rect. rect is in viewport coordinates.


items

public final java.util.List<QGraphicsItemInterface> items(QRect rect,
                                                          Qt.ItemSelectionMode mode)

Returns a list of all the items that, depending on mode, are either contained by or intersect with rect. rect is in viewport coordinates.

The default value for mode is Qt::IntersectsItemShape; all items whose exact shape intersects with or is contained by rect are returned.

See Also:
itemAt, items, mapToScene

items

public final java.util.List<QGraphicsItemInterface> items(int x,
                                                          int y,
                                                          int w,
                                                          int h)
This convenience function is equivalent to calling items(QRectF(x, y, w, h)).


items

public final java.util.List<QGraphicsItemInterface> items(int x,
                                                          int y,
                                                          int w,
                                                          int h,
                                                          Qt.ItemSelectionMode mode)

This convenience function is equivalent to calling items(QRectF(x, y, w, h), mode).


items

public final java.util.List<QGraphicsItemInterface> items(QPolygon polygon)
Returns a list of all the items that are either contained by or intersect with polygon. polygon is in viewport coordinates.


items

public final java.util.List<QGraphicsItemInterface> items(QPolygon polygon,
                                                          Qt.ItemSelectionMode mode)

Returns a list of all the items that, depending on mode, are either contained by or intersect with polygon. polygon is in viewport coordinates.

The default value for mode is Qt::IntersectsItemShape; all items whose exact shape intersects with or is contained by polygon are returned.

See Also:
itemAt, items, mapToScene

items

public final java.util.List<QGraphicsItemInterface> items()

Returns a list of all the items in the associated scene.

See Also:
QGraphicsScene::items

items

public final java.util.List<QGraphicsItemInterface> items(QPainterPath path)
Returns a list of all the items that are either contained by or intersect with path.


items

public final java.util.List<QGraphicsItemInterface> items(QPainterPath path,
                                                          Qt.ItemSelectionMode mode)

Returns a list of all the items that, depending on mode, are either contained by or intersect with path. path is in viewport coordinates.

The default value for mode is Qt::IntersectsItemShape; all items whose exact shape intersects with or is contained by path are returned.

See Also:
itemAt, items, mapToScene

items

public final java.util.List<QGraphicsItemInterface> items(int x,
                                                          int y)

This function is provided for convenience. It's equivalent to calling items(QPoint(x, y)).


items

public final java.util.List<QGraphicsItemInterface> items(QPoint pos)

Returns a list of all the items at the position pos in the view. The items are listed in descending Z order (i.e., the first item in the list is the top-most item, and the last item is the bottom-most item). pos is in viewport coordinates.

This function is most commonly called from within mouse event handlers in a subclass in QGraphicsView. pos is in untransformed viewport coordinates, just like QMouseEvent::pos().

    void CustomView::mousePressEvent(QMouseEvent *event)
    {
        qDebug() << "There are" << items(event->pos()).size()
                 << "items at position" << mapToScene(event->pos());
    }

See Also:
QGraphicsScene::items, QGraphicsItem::zValue

mapFromScene

public final QPainterPath mapFromScene(QPainterPath path)

Returns the scene coordinate painter path path to a viewport coordinate painter path.

See Also:
mapToScene

mapFromScene

public final QPolygon mapFromScene(double x,
                                   double y,
                                   double w,
                                   double h)

This function is provided for convenience. It's equivalent to calling mapFromScene(QRectF(x, y, w, h)).


mapFromScene

public final QPoint mapFromScene(QPointF point)

Returns the scene coordinate point to viewport coordinates.

See Also:
mapToScene

mapFromScene

public final QPolygon mapFromScene(QRectF rect)

Returns the scene rectangle rect to a viewport coordinate polygon.

See Also:
mapToScene

mapFromScene

public final QPoint mapFromScene(double x,
                                 double y)

This function is provided for convenience. It's equivalent to calling mapFromScene(QPointF(x, y)).


mapFromScene

public final QPolygon mapFromScene(QPolygonF polygon)

Returns the scene coordinate polygon polygon to a viewport coordinate polygon.

See Also:
mapToScene

mapToScene

public final QPainterPath mapToScene(QPainterPath path)

Returns the viewport painter path path mapped to a scene coordinate painter path.

See Also:
mapFromScene

mapToScene

public final QPolygonF mapToScene(int x,
                                  int y,
                                  int w,
                                  int h)

This function is provided for convenience. It's equivalent to calling mapToScene(QRect(x, y, w, h)).


mapToScene

public final QPolygonF mapToScene(QRect rect)

Returns the viewport rectangle rect mapped to a scene coordinate polygon.

See Also:
mapFromScene

mapToScene

public final QPointF mapToScene(QPoint point)

Returns the viewport coordinate point mapped to scene coordinates.

Note: It can be useful to map the whole rectangle covered by the pixel at point instead of the point itself. To do this, you can call mapToScene(QRect(point, QSize(2, 2))).

See Also:
mapFromScene

mapToScene

public final QPolygonF mapToScene(QPolygon polygon)

Returns the viewport polygon polygon mapped to a scene coordinate polygon.

See Also:
mapFromScene

mapToScene

public final QPointF mapToScene(int x,
                                int y)

This function is provided for convenience. It's equivalent to calling mapToScene(QPoint(x, y)).


matrix

public final QMatrix matrix()

Returns the current transformation matrix for the view. If no current transformation is set, the identity matrix is returned.

See Also:
setMatrix, rotate, scale, shear, translate

optimizationFlags

public final QGraphicsView.OptimizationFlags optimizationFlags()

Returns flags that can be used to tune QGraphicsView's performance..

QGraphicsView uses clipping, extra bounding rect adjustments, and certain other aids to improve rendering quality and performance for the common case graphics scene. However, depending on the target platform, the scene, and the viewport in use, some of these operations can degrade performance.

The effect varies from flag to flag; see the OptimizationFlags documentation for details.

By default, no optimization flags are enabled.

See Also:
setOptimizationFlags, setOptimizationFlag

render

public final void render(QPainter painter,
                         QRectF target,
                         QRect source)

Equivalent to render(painter, target, source, Qt::KeepAspectRatio).


render

public final void render(QPainter painter,
                         QRectF target)

Equivalent to render(painter, target, QRect(), Qt::KeepAspectRatio).


render

public final void render(QPainter painter)

Equivalent to render(painter, QRectF(), QRect(), Qt::KeepAspectRatio).


render

public final void render(QPainter painter,
                         QRectF target,
                         QRect source,
                         Qt.AspectRatioMode aspectRatioMode)

Renders the source rect, which is in view coordinates, from the scene into target, which is in paint device coordinates, using painter. This function is useful for capturing the contents of the view onto a paint device, such as a QImage (e.g., to take a screenshot), or for printing to QPrinter. For example:

    QGraphicsScene scene;
    scene.addItem(...
    ...

    QGraphicsView view(&scene);
    view.show();
    ...

    QPrinter printer(QPrinter::HighResolution);
    printer.setPageSize(QPrinter::A4);
    QPainter painter(&printer);

    // print, fitting the viewport contents into a full page
    view.render(&painter);

    // print the upper half of the viewport into the lower.
    // half of the page.
    QRect viewport = view.viewport()->rect();
    view.render(&painter,
                QRectF(0, printer.height() / 2,
                       printer.width(), printer.height() / 2),
                viewport.adjusted(0, 0, 0, -viewport.height() / 2));

If source is a null rect, this function will use viewport->rect to determine what to draw. If target is a null rect, the full dimensions of painter's paint device (e.g., for a QPrinter, the page size) will be used.

The source rect contents will be transformed according to aspectRatioMode to fit into the target rect. By default, the aspect ratio is kept, and source is scaled to fit in target.

See Also:
QGraphicsScene::render

renderHints

public final QPainter.RenderHints renderHints()

Returns the default render hints for the view.

These hints are used to initialize QPainter before each visible item is drawn. QPainter uses render hints to toggle rendering features such as antialiasing and smooth pixmap transformation.

QPainter::TextAntialiasing is enabled by default.

Example:

    QGraphicsScene scene;
    scene.addRect(QRectF(-10, -10, 20, 20));

    QGraphicsView view(&scene);
    view.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
    view.show();

See Also:
setRenderHints

resetCachedContent

public final void resetCachedContent()

Resets any cached content. Calling this function will clear QGraphicsView's cache. If the current cache mode is CacheNone, this function does nothing.

This function is called automatically for you when the backgroundBrush or QGraphicsScene::backgroundBrush properties change; you only need to call this function if you have reimplemented QGraphicsScene::drawBackground() or QGraphicsView::drawBackground() to draw a custom background, and need to trigger a full redraw.

See Also:
cacheMode

resetMatrix

public final void resetMatrix()

Resets the view transformation matrix to the identity matrix.


resetTransform

public final void resetTransform()

Resets the view transformation to the identity matrix.

See Also:
transform, setTransform

resizeAnchor

public final QGraphicsView.ViewportAnchor resizeAnchor()

Returns how the view should position the scene when the view is resized..

QGraphicsView uses this property to decide how to position the scene in the viewport when the viewport widget's size changes. The default behavior, NoAnchor, leaves the scene's position unchanged during a resize; the top-left corner of the view will appear to be anchored while resizing.

Note that the effect of this property is noticeable when only a part of the scene is visible (i.e., when there are scroll bars). Otherwise, if the whole scene fits in the view, QGraphicsScene uses the view alignment to position the scene in the view.

See Also:
setResizeAnchor, alignment, transformationAnchor, Qt::WNorthWestGravity

rotate

public final void rotate(double angle)

Rotates the current view transformation angle degrees clockwise.

See Also:
setMatrix, matrix, scale, shear, translate

rubberBandSelectionMode

public final Qt.ItemSelectionMode rubberBandSelectionMode()

Returns the behavior for selecting items with a rubber band selection rectangle..

This property defines how items are selected when using the RubberBandDrag drag mode.

The default value is Qt::IntersectsItemShape; all items whose shape intersects with or is contained by the rubber band are selected.

See Also:
setRubberBandSelectionMode, dragMode, items

scale

public final void scale(double sx,
                        double sy)

Scales the current view transformation by (sx, sy).

See Also:
setMatrix, matrix, rotate, shear, translate

scene

public final QGraphicsScene scene()

Returns a pointer to the scene that is currently visualized in the view. If no scene is currently visualized, 0 is returned.

See Also:
setScene

sceneRect

public final QRectF sceneRect()

Returns the area of the scene visualized by this view..

The scene rect defines the extent of the scene, and in the view's case, this means the area of the scene that you can navigate using the scroll bars.

If unset, or if a null QRectF is set, this property has the same value as QGraphicsScene::sceneRect, and it changes with QGraphicsScene::sceneRect. Otherwise, the view's scene rect is unaffected by the scene.

Note that although the scene supports a virtually unlimited size, the range of the scroll bars will never exceed the range of an integer (INT_MIN, INT_MAX). When the scene is larger than the scroll bars' values, you can choose to use translate to navigate the scene instead.

See Also:
setSceneRect, QGraphicsScene::sceneRect

setAlignment

public final void setAlignment(Qt.AlignmentFlag... alignment)

Sets the alignment of the scene in the view when the whole scene is visible. to alignment.

If the whole scene is visible in the view, (i.e., there are no visible scroll bars,) the view's alignment will decide where the scene will be rendered in the view. For example, if the alignment is Qt::AlignCenter, which is default, the scene will be centered in the view, and if the alignment is (Qt::AlignLeft | Qt::AlignTop), the scene will be rendered in the top-left corner of the view.

See Also:
alignment

setAlignment

public final void setAlignment(Qt.Alignment alignment)

Sets the alignment of the scene in the view when the whole scene is visible. to alignment.

If the whole scene is visible in the view, (i.e., there are no visible scroll bars,) the view's alignment will decide where the scene will be rendered in the view. For example, if the alignment is Qt::AlignCenter, which is default, the scene will be centered in the view, and if the alignment is (Qt::AlignLeft | Qt::AlignTop), the scene will be rendered in the top-left corner of the view.

See Also:
alignment

setBackgroundBrush

public final void setBackgroundBrush(QBrush brush)

Sets the background brush of the scene. to brush.

This property sets the background brush for the scene in this view. It is used to override the scene's own background, and defines the behavior of drawBackground. To provide custom background drawing for this view, you can reimplement drawBackground instead.

See Also:
QGraphicsScene::backgroundBrush, foregroundBrush

setCacheMode

public final void setCacheMode(QGraphicsView.CacheModeFlag... mode)

Sets which parts of the view are cached to mode.

QGraphicsView can cache pre-rendered content in a QPixmap, which is then drawn onto the viewport. The purpose of such caching is to speed up the total rendering time for areas that are slow to render. Texture, gradient and alpha blended backgrounds, for example, can be notibly slow to render; especially with a transformed view. The CacheBackground flag enables caching of the view's background. For example:

    QGraphicsView view;
    view.setBackgroundBrush(":/images/backgroundtile.png");
    view.setCacheMode(QGraphicsView::CacheBackground);

The cache is invalidated every time the view is transformed. However, when scrolling, only partial invalidation is required.

By default, nothing is cached.

See Also:
cacheMode, resetCachedContent, QPixmapCache

setCacheMode

public final void setCacheMode(QGraphicsView.CacheMode mode)

Sets which parts of the view are cached to mode.

QGraphicsView can cache pre-rendered content in a QPixmap, which is then drawn onto the viewport. The purpose of such caching is to speed up the total rendering time for areas that are slow to render. Texture, gradient and alpha blended backgrounds, for example, can be notibly slow to render; especially with a transformed view. The CacheBackground flag enables caching of the view's background. For example:

    QGraphicsView view;
    view.setBackgroundBrush(":/images/backgroundtile.png");
    view.setCacheMode(QGraphicsView::CacheBackground);

The cache is invalidated every time the view is transformed. However, when scrolling, only partial invalidation is required.

By default, nothing is cached.

See Also:
cacheMode, resetCachedContent, QPixmapCache

setDragMode

public final void setDragMode(QGraphicsView.DragMode mode)

Sets the behavior for dragging the mouse over the scene while the left mouse button is pressed. to mode.

This property defines what should happen when the user clicks on the scene background and drags the mouse (e.g., scrolling the viewport contents using a pointing hand cursor, or selecting multiple items with a rubber band). The default value, NoDrag, does nothing.

This behavior only affects mouse clicks that are not handled by any item. You can define a custom behavior by creating a subclass of QGraphicsView and reimplementing mouseMoveEvent.

See Also:
dragMode

setForegroundBrush

public final void setForegroundBrush(QBrush brush)

Sets the foreground brush of the scene. to brush.

This property sets the foreground brush for the scene in this view. It is used to override the scene's own foreground, and defines the behavior of drawForeground. To provide custom background drawing for this view, you can reimplement drawBackground instead.

See Also:
QGraphicsScene::foregroundBrush, backgroundBrush

setInteractive

public final void setInteractive(boolean allowed)

Sets whether the view allowed scene interaction. to allowed.

If enabled, this view is set to allow scene interaction. Otherwise, this view will not allow interaction, and any mouse or key events are ignored (i.e., it will act as a read-only view).

See Also:
isInteractive

setMatrix

public final void setMatrix(QMatrix matrix)

Equivalent to setMatrix(matrix, false).


setMatrix

public final void setMatrix(QMatrix matrix,
                            boolean combine)

Sets the view's current transformation matrix to matrix.

If combine is true, then matrix is combined with the current matrix; otherwise, matrix replaces the current matrix. combine is false by default.

The transformation matrix tranforms the scene into view coordinates. Using the default transformation, provided by the identity matrix, one pixel in the view represents one unit in the scene (e.g., a 10x10 rectangular item is drawn using 10x10 pixels in the view). If a 2x2 scaling matrix is applied, the scene will be drawn in 1:2 (e.g., a 10x10 rectangular item is then drawn using 20x20 pixels in the view).

Example:

    QGraphicsScene scene;
    scene.addText("GraphicsView rotated clockwise");

    QGraphicsView view(&scene);
    view.rotate(90); // the text is rendered with a 90 degree clockwise rotation
    view.show();

To simplify interation with items using a transformed view, QGraphicsView provides mapTo... and mapFrom... functions that can translate between scene and view coordinates. For example, you can call mapToScene to map a view coordinate to a floating point scene coordinate, or mapFromScene to map from floating point scene coordinates to view coordinates.

See Also:
matrix, rotate, scale, shear, translate

setOptimizationFlag

public final void setOptimizationFlag(QGraphicsView.OptimizationFlag flag)

Equivalent to setOptimizationFlag(flag, true).


setOptimizationFlag

public final void setOptimizationFlag(QGraphicsView.OptimizationFlag flag,
                                      boolean enabled)

Enables flag if enabled is true; otherwise disables flag.

See Also:
optimizationFlags

setOptimizationFlags

public final void setOptimizationFlags(QGraphicsView.OptimizationFlag... flags)

Sets flags that can be used to tune QGraphicsView's performance. to flags.

QGraphicsView uses clipping, extra bounding rect adjustments, and certain other aids to improve rendering quality and performance for the common case graphics scene. However, depending on the target platform, the scene, and the viewport in use, some of these operations can degrade performance.

The effect varies from flag to flag; see the OptimizationFlags documentation for details.

By default, no optimization flags are enabled.

See Also:
optimizationFlags, setOptimizationFlag

setOptimizationFlags

public final void setOptimizationFlags(QGraphicsView.OptimizationFlags flags)

Sets flags that can be used to tune QGraphicsView's performance. to flags.

QGraphicsView uses clipping, extra bounding rect adjustments, and certain other aids to improve rendering quality and performance for the common case graphics scene. However, depending on the target platform, the scene, and the viewport in use, some of these operations can degrade performance.

The effect varies from flag to flag; see the OptimizationFlags documentation for details.

By default, no optimization flags are enabled.

See Also:
optimizationFlags, setOptimizationFlag

setRenderHint

public final void setRenderHint(QPainter.RenderHint hint)

Equivalent to setRenderHint(hint, true).


setRenderHint

public final void setRenderHint(QPainter.RenderHint hint,
                                boolean enabled)

If enabled is true, the render hint hint is enabled; otherwise it is disabled.

See Also:
renderHints

setRenderHints

public final void setRenderHints(QPainter.RenderHint... hints)

Sets the default render hints for the view to hints.

These hints are used to initialize QPainter before each visible item is drawn. QPainter uses render hints to toggle rendering features such as antialiasing and smooth pixmap transformation.

QPainter::TextAntialiasing is enabled by default.

Example:

    QGraphicsScene scene;
    scene.addRect(QRectF(-10, -10, 20, 20));

    QGraphicsView view(&scene);
    view.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
    view.show();

See Also:
renderHints

setRenderHints

public final void setRenderHints(QPainter.RenderHints hints)

Sets the default render hints for the view to hints.

These hints are used to initialize QPainter before each visible item is drawn. QPainter uses render hints to toggle rendering features such as antialiasing and smooth pixmap transformation.

QPainter::TextAntialiasing is enabled by default.

Example:

    QGraphicsScene scene;
    scene.addRect(QRectF(-10, -10, 20, 20));

    QGraphicsView view(&scene);
    view.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
    view.show();

See Also:
renderHints

setResizeAnchor

public final void setResizeAnchor(QGraphicsView.ViewportAnchor anchor)

Sets how the view should position the scene when the view is resized. to anchor.

QGraphicsView uses this property to decide how to position the scene in the viewport when the viewport widget's size changes. The default behavior, NoAnchor, leaves the scene's position unchanged during a resize; the top-left corner of the view will appear to be anchored while resizing.

Note that the effect of this property is noticeable when only a part of the scene is visible (i.e., when there are scroll bars). Otherwise, if the whole scene fits in the view, QGraphicsScene uses the view alignment to position the scene in the view.

See Also:
resizeAnchor, alignment, transformationAnchor, Qt::WNorthWestGravity

setRubberBandSelectionMode

public final void setRubberBandSelectionMode(Qt.ItemSelectionMode mode)

Sets the behavior for selecting items with a rubber band selection rectangle. to mode.

This property defines how items are selected when using the RubberBandDrag drag mode.

The default value is Qt::IntersectsItemShape; all items whose shape intersects with or is contained by the rubber band are selected.

See Also:
rubberBandSelectionMode, dragMode, items

setScene

public final void setScene(QGraphicsScene scene)

Sets the current scene to scene. If scene is already being viewed, this function does nothing.

When a scene is set on a view, the QGraphicsScene::changed() signal is automatically connected to this view's updateScene slot, and the view's scroll bars are adjusted to fit the size of the scene.

See Also:
scene

setSceneRect

public final void setSceneRect(double x,
                               double y,
                               double w,
                               double h)

Sets the area of the scene visualized by this view..

The scene rect defines the extent of the scene, and in the view's case, this means the area of the scene that you can navigate using the scroll bars.

If unset, or if a null QRectF is set, this property has the same value as QGraphicsScene::sceneRect, and it changes with QGraphicsScene::sceneRect. Otherwise, the view's scene rect is unaffected by the scene.

Note that although the scene supports a virtually unlimited size, the range of the scroll bars will never exceed the range of an integer (INT_MIN, INT_MAX). When the scene is larger than the scroll bars' values, you can choose to use translate to navigate the scene instead.

See Also:
QGraphicsScene::sceneRect

setSceneRect

public final void setSceneRect(QRectF rect)

Sets the area of the scene visualized by this view. to rect.

The scene rect defines the extent of the scene, and in the view's case, this means the area of the scene that you can navigate using the scroll bars.

If unset, or if a null QRectF is set, this property has the same value as QGraphicsScene::sceneRect, and it changes with QGraphicsScene::sceneRect. Otherwise, the view's scene rect is unaffected by the scene.

Note that although the scene supports a virtually unlimited size, the range of the scroll bars will never exceed the range of an integer (INT_MIN, INT_MAX). When the scene is larger than the scroll bars' values, you can choose to use translate to navigate the scene instead.

See Also:
QGraphicsScene::sceneRect

setTransform

public final void setTransform(QTransform matrix)

Equivalent to setTransform(matrix, false).


setTransform

public final void setTransform(QTransform matrix,
                               boolean combine)

Sets the view's current transformation matrix to matrix.

If combine is true, then matrix is combined with the current matrix; otherwise, matrix replaces the current matrix. combine is false by default.

The transformation matrix tranforms the scene into view coordinates. Using the default transformation, provided by the identity matrix, one pixel in the view represents one unit in the scene (e.g., a 10x10 rectangular item is drawn using 10x10 pixels in the view). If a 2x2 scaling matrix is applied, the scene will be drawn in 1:2 (e.g., a 10x10 rectangular item is then drawn using 20x20 pixels in the view).

Example:

    QGraphicsScene scene;
    scene.addText("GraphicsView rotated clockwise");

    QGraphicsView view(&scene);
    view.rotate(90); // the text is rendered with a 90 degree clockwise rotation
    view.show();

To simplify interation with items using a transformed view, QGraphicsView provides mapTo... and mapFrom... functions that can translate between scene and view coordinates. For example, you can call mapToScene to map a view coordiate to a floating point scene coordinate, or mapFromScene to map from floating point scene coordinates to view coordinates.

See Also:
transform, rotate, scale, shear, translate

setTransformationAnchor

public final void setTransformationAnchor(QGraphicsView.ViewportAnchor anchor)

Sets how the view should position the scene during transformations. to anchor.

QGraphicsView uses this property to decide how to position the scene in the viewport when the transformation matrix changes, and the coordinate system of the view is transformed. The default behavior, AnchorViewCenter, ensures that the scene point at the center of the view remains unchanged during transformations (e.g., when rotating, the scene will appear to rotate around the center of the view).

Note that the effect of this property is noticeable when only a part of the scene is visible (i.e., when there are scroll bars). Otherwise, if the whole scene fits in the view, QGraphicsScene uses the view alignment to position the scene in the view.

See Also:
transformationAnchor, alignment, resizeAnchor

setViewportUpdateMode

public final void setViewportUpdateMode(QGraphicsView.ViewportUpdateMode mode)

Sets how the viewport should update its contents. to mode.

QGraphicsView uses this property to decide how to update areas of the scene that have been reexposed or changed. Usually you do not need to modify this property, but there are some cases where doing so can improve rendering performance. See the ViewportUpdateMode documentation for specific details.

The default value is MinimalViewportUpdate, where QGraphicsView will update as small an area of the viewport as possible when the contents change.

See Also:
viewportUpdateMode, ViewportUpdateMode, cacheMode

setupViewport

protected void setupViewport(QWidget widget)

This slot is called by QAbstractScrollArea after setViewport has been called. Reimplement this function in a subclass of QGraphicsView to initialize the new viewport widget before it is used.

Overrides:
setupViewport in class QAbstractScrollArea
See Also:
setViewport

shear

public final void shear(double sh,
                        double sv)

Shears the current view transformation by (sh, sv).

See Also:
setMatrix, matrix, rotate, scale, translate

transform

public final QTransform transform()

Returns the current transformation matrix for the view. If no current transformation is set, the identity matrix is returned.

See Also:
setTransform, rotate, scale, shear, translate

transformationAnchor

public final QGraphicsView.ViewportAnchor transformationAnchor()

Returns how the view should position the scene during transformations..

QGraphicsView uses this property to decide how to position the scene in the viewport when the transformation matrix changes, and the coordinate system of the view is transformed. The default behavior, AnchorViewCenter, ensures that the scene point at the center of the view remains unchanged during transformations (e.g., when rotating, the scene will appear to rotate around the center of the view).

Note that the effect of this property is noticeable when only a part of the scene is visible (i.e., when there are scroll bars). Otherwise, if the whole scene fits in the view, QGraphicsScene uses the view alignment to position the scene in the view.

See Also:
setTransformationAnchor, alignment, resizeAnchor

translate

public final void translate(double dx,
                            double dy)

Translates the current view transformation by (dx, dy).

See Also:
setMatrix, matrix, rotate, shear

updateScene

public final void updateScene(java.util.List<QRectF> rects)

Schedules an update of the scene rectangles rects.

See Also:
QGraphicsScene::changed

updateSceneRect

public final void updateSceneRect(QRectF rect)

Notifies QGraphicsView that the scene's scene rect has changed. rect is the new scene rect. If the view already has an explicitly set scene rect, this function does nothing.

See Also:
sceneRect, QGraphicsScene::sceneRectChanged

viewportTransform

public final QTransform viewportTransform()

Returns a matrix that maps viewport coordinates to scene coordinates.

See Also:
mapToScene, mapFromScene

viewportUpdateMode

public final QGraphicsView.ViewportUpdateMode viewportUpdateMode()

Returns how the viewport should update its contents..

QGraphicsView uses this property to decide how to update areas of the scene that have been reexposed or changed. Usually you do not need to modify this property, but there are some cases where doing so can improve rendering performance. See the ViewportUpdateMode documentation for specific details.

The default value is MinimalViewportUpdate, where QGraphicsView will update as small an area of the viewport as possible when the contents change.

See Also:
setViewportUpdateMode, ViewportUpdateMode, cacheMode

contextMenuEvent

protected void contextMenuEvent(QContextMenuEvent event)

This function is reimplemented for internal reasons.

Overrides:
contextMenuEvent in class QAbstractScrollArea
See Also:
QWidget::contextMenuEvent

dragEnterEvent

protected void dragEnterEvent(QDragEnterEvent event)

This function is reimplemented for internal reasons.

Overrides:
dragEnterEvent in class QAbstractScrollArea
See Also:
QWidget::dragEnterEvent

dragLeaveEvent

protected void dragLeaveEvent(QDragLeaveEvent event)

This function is reimplemented for internal reasons.

Overrides:
dragLeaveEvent in class QAbstractScrollArea
See Also:
QWidget::dragLeaveEvent

dragMoveEvent

protected void dragMoveEvent(QDragMoveEvent event)

This function is reimplemented for internal reasons.

Overrides:
dragMoveEvent in class QAbstractScrollArea
See Also:
QWidget::dragMoveEvent

drawBackground

protected void drawBackground(QPainter painter,
                              QRectF rect)

Draws the background of the scene using painter, before any items and the foreground are drawn. Reimplement this function to provide a custom background for this view.

If all you want is to define a color, texture or gradient for the background, you can call setBackgroundBrush instead.

All painting is done in scene coordinates. rect is the exposed rectangle.

The default implementation fills rect using the view's backgroundBrush. If no such brush is defined (the default), the scene's drawBackground function is called instead.

See Also:
drawForeground, QGraphicsScene::drawForeground

drawForeground

protected void drawForeground(QPainter painter,
                              QRectF rect)

Draws the foreground of the scene using painter, after the background and all items are drawn. Reimplement this function to provide a custom foreground for this view.

If all you want is to define a color, texture or gradient for the foreground, you can call setForegroundBrush instead.

All painting is done in scene coordinates. rect is the exposed rectangle.

The default implementation fills rect using the view's foregroundBrush. If no such brush is defined (the default), the scene's drawForeground function is called instead.

See Also:
drawBackground, QGraphicsScene::drawBackground

drawItems

protected void drawItems(QPainter painter,
                         QGraphicsItemInterface[] items,
                         QStyleOptionGraphicsItem[] options)

Equivalent to drawItems(painter, items, options, ).


dropEvent

protected void dropEvent(QDropEvent event)

This function is reimplemented for internal reasons.

Overrides:
dropEvent in class QAbstractScrollArea
See Also:
QWidget::dropEvent

event

public boolean event(QEvent event)

This function is reimplemented for internal reasons.

Overrides:
event in class QAbstractScrollArea
See Also:
QEvent::type

focusInEvent

protected void focusInEvent(QFocusEvent event)

This function is reimplemented for internal reasons.

Overrides:
focusInEvent in class QWidget
See Also:
focusOutEvent, setFocusPolicy, keyPressEvent, keyReleaseEvent, event, QFocusEvent

focusOutEvent

protected void focusOutEvent(QFocusEvent event)

This function is reimplemented for internal reasons.

Overrides:
focusOutEvent in class QWidget
See Also:
focusInEvent, setFocusPolicy, keyPressEvent, keyReleaseEvent, event, QFocusEvent

inputMethodEvent

protected void inputMethodEvent(QInputMethodEvent event)

This function is reimplemented for internal reasons.

Overrides:
inputMethodEvent in class QWidget
See Also:
event, QInputMethodEvent

inputMethodQuery

public java.lang.Object inputMethodQuery(Qt.InputMethodQuery query)

This function is reimplemented for internal reasons.

Overrides:
inputMethodQuery in class QWidget
See Also:
inputMethodEvent, QInputMethodEvent, QInputContext

keyPressEvent

protected void keyPressEvent(QKeyEvent event)

This function is reimplemented for internal reasons.

Overrides:
keyPressEvent in class QAbstractScrollArea
See Also:
keyReleaseEvent, QKeyEvent::ignore, setFocusPolicy, focusInEvent, focusOutEvent, event, QKeyEvent, Tetrix Example

keyReleaseEvent

protected void keyReleaseEvent(QKeyEvent event)

This function is reimplemented for internal reasons.

Overrides:
keyReleaseEvent in class QWidget
See Also:
keyPressEvent, QKeyEvent::ignore, setFocusPolicy, focusInEvent, focusOutEvent, event, QKeyEvent

mouseDoubleClickEvent

protected void mouseDoubleClickEvent(QMouseEvent event)

This function is reimplemented for internal reasons.

Overrides:
mouseDoubleClickEvent in class QAbstractScrollArea
See Also:
QWidget::mouseDoubleClickEvent

mouseMoveEvent

protected void mouseMoveEvent(QMouseEvent event)

This function is reimplemented for internal reasons.

Overrides:
mouseMoveEvent in class QAbstractScrollArea
See Also:
QWidget::mouseMoveEvent

mousePressEvent

protected void mousePressEvent(QMouseEvent event)

This function is reimplemented for internal reasons.

Overrides:
mousePressEvent in class QAbstractScrollArea
See Also:
QWidget::mousePressEvent

mouseReleaseEvent

protected void mouseReleaseEvent(QMouseEvent event)

This function is reimplemented for internal reasons.

Overrides:
mouseReleaseEvent in class QAbstractScrollArea
See Also:
QWidget::mouseReleaseEvent

paintEvent

protected void paintEvent(QPaintEvent event)

This function is reimplemented for internal reasons.

Overrides:
paintEvent in class QAbstractScrollArea
See Also:
QWidget::paintEvent

resizeEvent

protected void resizeEvent(QResizeEvent event)

This function is reimplemented for internal reasons.

Overrides:
resizeEvent in class QAbstractScrollArea
See Also:
QWidget::resizeEvent

scrollContentsBy

protected void scrollContentsBy(int dx,
                                int dy)

This function is reimplemented for internal reasons.

Overrides:
scrollContentsBy in class QAbstractScrollArea

showEvent

protected void showEvent(QShowEvent event)

This function is reimplemented for internal reasons.

Overrides:
showEvent in class QWidget
See Also:
visible, event, QShowEvent

sizeHint

public QSize sizeHint()

This function is reimplemented for internal reasons.

Overrides:
sizeHint in class QAbstractScrollArea
See Also:
QSize::isValid, minimumSizeHint, sizePolicy, setMinimumSize, updateGeometry

viewportEvent

protected boolean viewportEvent(QEvent event)

This function is reimplemented for internal reasons.

Overrides:
viewportEvent in class QAbstractScrollArea

wheelEvent

protected void wheelEvent(QWheelEvent event)

This function is reimplemented for internal reasons.

Overrides:
wheelEvent in class QAbstractScrollArea
See Also:
QWidget::wheelEvent

fromNativePointer

public static QGraphicsView fromNativePointer(QNativePointer nativePointer)
This function returns the QGraphicsView instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.