Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

Public Types | Public Slots | Signals | Public Member Functions | Static Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes | Properties | Private Member Functions | Friends | Related Functions

QGraphicsView Class Reference

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

Inheritance diagram for QGraphicsView:
Inheritance graph
[legend]
Collaboration diagram for QGraphicsView:
Collaboration graph
[legend]

List of all members.

Public Types

enum  CacheModeFlag { CacheNone = 0x0, CacheBackground = 0x1 }
enum  DragMode { NoDrag, ScrollHandDrag, RubberBandDrag }
enum  OptimizationFlag { DontClipPainter = 0x1, DontSavePainterState = 0x2, DontAdjustForAntialiasing = 0x4 }
enum  PaintDeviceMetric {
  PdmWidth = 1, PdmHeight, PdmWidthMM, PdmHeightMM,
  PdmNumColors, PdmDepth, PdmDpiX, PdmDpiY,
  PdmPhysicalDpiX, PdmPhysicalDpiY
}
enum  RenderFlag { DrawWindowBackground = 0x1, DrawChildren = 0x2, IgnoreMask = 0x4 }
enum  Shadow { Plain = 0x0010, Raised = 0x0020, Sunken = 0x0030 }
enum  Shape {
  NoFrame = 0, Box = 0x0001, Panel = 0x0002, WinPanel = 0x0003,
  HLine = 0x0004, VLine = 0x0005, StyledPanel = 0x0006
}
enum  StyleMask { Shadow_Mask = 0x00f0, Shape_Mask = 0x000f }
enum  ViewportAnchor { NoAnchor, AnchorViewCenter, AnchorUnderMouse }
enum  ViewportUpdateMode {
  FullViewportUpdate, MinimalViewportUpdate, SmartViewportUpdate, NoViewportUpdate,
  BoundingRectViewportUpdate
}

Public Slots

bool close ()
void hide ()
void invalidateScene (const QRectF &rect=QRectF(), QGraphicsScene::SceneLayers layers=QGraphicsScene::AllLayers)
void lower ()
void raise ()
void repaint ()
void setDisabled (bool)
void setEnabled (bool)
void setFocus ()
void setHidden (bool hidden)
QT_MOC_COMPAT void setShown (bool shown)
void setStyleSheet (const QString &styleSheet)
virtual void setVisible (bool visible)
void setWindowModified (bool)
void setWindowTitle (const QString &)
void show ()
void showFullScreen ()
void showMaximized ()
void showMinimized ()
void showNormal ()
void update ()
void updateScene (const QList< QRectF > &rects)
void updateSceneRect (const QRectF &rect)

Signals

void customContextMenuRequested (const QPoint &pos)

Public Member Functions

bool acceptDrops () const
QString accessibleDescription () const
QString accessibleName () const
QList< QAction * > actions () const
void activateWindow ()
void addAction (QAction *action)
void addActions (QList< QAction * > actions)
void addScrollBarWidget (QWidget *widget, Qt::Alignment alignment)
void adjustSize ()
Qt::Alignment alignment () const
bool autoFillBackground () const
QBrush backgroundBrush () const
QPalette::ColorRole backgroundRole () const
QSize baseSize () const
CacheMode cacheMode () const
void centerOn (const QPointF &pos)
void centerOn (qreal x, qreal y)
void centerOn (const QGraphicsItem *item)
QWidgetchildAt (int x, int y) const
QWidgetchildAt (const QPoint &p) const
QRect childrenRect () const
QRegion childrenRegion () const
void clearFocus ()
void clearMask ()
QRect contentsRect () const
Qt::ContextMenuPolicy contextMenuPolicy () const
QWidgetcornerWidget () const
void createWinId ()
QCursor cursor () const
int depth () const
int devType () const
DragMode dragMode () const
WId effectiveWinId () const
void ensurePolished () const
void ensureVisible (const QRectF &rect, int xmargin=50, int ymargin=50)
void ensureVisible (const QGraphicsItem *item, int xmargin=50, int ymargin=50)
void ensureVisible (qreal x, qreal y, qreal w, qreal h, int xmargin=50, int ymargin=50)
void fitInView (const QRectF &rect, Qt::AspectRatioMode aspectRadioMode=Qt::IgnoreAspectRatio)
void fitInView (qreal x, qreal y, qreal w, qreal h, Qt::AspectRatioMode aspectRadioMode=Qt::IgnoreAspectRatio)
void fitInView (const QGraphicsItem *item, Qt::AspectRatioMode aspectRadioMode=Qt::IgnoreAspectRatio)
Qt::FocusPolicy focusPolicy () const
QWidgetfocusProxy () const
QWidgetfocusWidget () const
const QFontfont () const
QFontInfo fontInfo () const
QFontMetrics fontMetrics () const
QBrush foregroundBrush () const
QPalette::ColorRole foregroundRole () const
QRect frameGeometry () const
QRect frameRect () const
Shadow frameShadow () const
Shape frameShape () const
QSize frameSize () const
int frameStyle () const
int frameWidth () const
const QRectgeometry () const
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
void grabKeyboard ()
void grabMouse ()
void grabMouse (const QCursor &)
int grabShortcut (const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
QGraphicsProxyWidgetgraphicsProxyWidget () const
Qt::HANDLE handle () const
bool hasFocus () const
bool hasMouseTracking () const
int height () const
virtual int heightForWidth (int) const
int heightMM () const
QScrollBarhorizontalScrollBar () const
Qt::ScrollBarPolicy horizontalScrollBarPolicy () const
QInputContextinputContext ()
QVariant inputMethodQuery (Qt::InputMethodQuery query) const
void insertAction (QAction *before, QAction *action)
void insertActions (QAction *before, QList< QAction * > actions)
WId internalWinId () const
bool isActiveWindow () const
bool isAncestorOf (const QWidget *child) const
bool isEnabled () const
bool isEnabledTo (QWidget *) const
bool isEnabledToTLW () const
bool isFullScreen () const
bool isHidden () const
bool isInteractive () const
bool isLeftToRight () const
bool isMaximized () const
bool isMinimized () const
bool isModal () const
bool isRightToLeft () const
bool isTopLevel () const
bool isVisible () const
bool isVisibleTo (QWidget *) const
bool isWindow () const
bool isWindowModified () const
QGraphicsItemitemAt (const QPoint &pos) const
QGraphicsItemitemAt (int x, int y) const
QList< QGraphicsItem * > items (const QPoint &pos) const
QList< QGraphicsItem * > items () const
QList< QGraphicsItem * > items (int x, int y, int w, int h, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
QList< QGraphicsItem * > items (const QRect &rect, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
QList< QGraphicsItem * > items (const QPolygon &polygon, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
QList< QGraphicsItem * > items (const QPainterPath &path, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
QList< QGraphicsItem * > items (int x, int y) const
QLayoutlayout () const
Qt::LayoutDirection layoutDirection () const
int lineWidth () const
QLocale locale () const
int logicalDpiX () const
int logicalDpiY () const
QPoint mapFrom (QWidget *, const QPoint &) const
QPoint mapFromGlobal (const QPoint &) const
QPoint mapFromParent (const QPoint &) const
QPolygon mapFromScene (const QRectF &rect) const
QPolygon mapFromScene (const QPolygonF &polygon) const
QPainterPath mapFromScene (const QPainterPath &path) const
QPoint mapFromScene (qreal x, qreal y) const
QPolygon mapFromScene (qreal x, qreal y, qreal w, qreal h) const
QPoint mapFromScene (const QPointF &point) const
QPoint mapTo (QWidget *, const QPoint &) const
QPoint mapToGlobal (const QPoint &) const
QPoint mapToParent (const QPoint &) const
QPolygonF mapToScene (const QPolygon &polygon) const
QPainterPath mapToScene (const QPainterPath &path) const
QPolygonF mapToScene (const QRect &rect) const
QPointF mapToScene (int x, int y) const
QPolygonF mapToScene (int x, int y, int w, int h) const
QPointF mapToScene (const QPoint &point) const
QRegion mask () const
QMatrix matrix () const
int maximumHeight () const
QSize maximumSize () const
QSize maximumViewportSize () const
int maximumWidth () const
int midLineWidth () const
int minimumHeight () const
QSize minimumSize () const
QSize minimumSizeHint () const
int minimumWidth () const
void move (int x, int y)
void move (const QPoint &)
QWidgetnativeParentWidget () const
QWidgetnextInFocusChain () const
QRect normalGeometry () const
int numColors () const
OptimizationFlags optimizationFlags () const
void overrideWindowFlags (Qt::WindowFlags type)
void overrideWindowState (Qt::WindowStates state)
QPaintEnginepaintEngine () const
bool paintingActive () const
const QPalettepalette () const
QWidgetparentWidget () const
int physicalDpiX () const
int physicalDpiY () const
QPoint pos () const
 QGraphicsView (QGraphicsScene *scene, QWidget *parent=0)
 QGraphicsView (QWidget *parent=0)
QRect rect () const
void releaseKeyboard ()
void releaseMouse ()
void releaseShortcut (int id)
void removeAction (QAction *action)
void render (QPainter *painter, const QRectF &target=QRectF(), const QRect &source=QRect(), Qt::AspectRatioMode aspectRatioMode=Qt::KeepAspectRatio)
void render (QPaintDevice *target, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
void render (QPainter *painter, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
QPainter::RenderHints renderHints () const
void repaint (const QRegion &)
void repaint (const QRect &)
void repaint (int x, int y, int w, int h)
void resetCachedContent ()
void resetMatrix ()
void resetTransform ()
void resize (int w, int h)
void resize (const QSize &)
ViewportAnchor resizeAnchor () const
bool restoreGeometry (const QByteArray &geometry)
void rotate (qreal angle)
Qt::ItemSelectionMode rubberBandSelectionMode () const
QByteArray saveGeometry () const
void scale (qreal sx, qreal sy)
QGraphicsScenescene () const
QRectF sceneRect () const
void scroll (int dx, int dy)
void scroll (int dx, int dy, const QRect &)
QWidgetList scrollBarWidgets (Qt::Alignment alignment)
void setAcceptDrops (bool on)
void setAccessibleDescription (const QString &description)
void setAccessibleName (const QString &name)
void setAlignment (Qt::Alignment alignment)
void setAttribute (Qt::WidgetAttribute, bool on=true)
void setAutoFillBackground (bool enabled)
void setBackgroundBrush (const QBrush &brush)
void setBackgroundRole (QPalette::ColorRole)
void setBaseSize (int basew, int baseh)
void setBaseSize (const QSize &)
void setCacheMode (CacheMode mode)
void setContentsMargins (int left, int top, int right, int bottom)
void setContextMenuPolicy (Qt::ContextMenuPolicy policy)
void setCornerWidget (QWidget *widget)
void setCursor (const QCursor &)
void setDragMode (DragMode mode)
void setFixedHeight (int h)
void setFixedSize (int w, int h)
void setFixedSize (const QSize &)
void setFixedWidth (int w)
void setFocus (Qt::FocusReason reason)
void setFocusPolicy (Qt::FocusPolicy policy)
void setFocusProxy (QWidget *)
void setFont (const QFont &)
void setForegroundBrush (const QBrush &brush)
void setForegroundRole (QPalette::ColorRole)
void setFrameRect (const QRect &)
void setFrameShadow (Shadow)
void setFrameShape (Shape)
void setFrameStyle (int)
void setGeometry (int x, int y, int w, int h)
void setGeometry (const QRect &)
void setHorizontalScrollBar (QScrollBar *scrollbar)
void setHorizontalScrollBarPolicy (Qt::ScrollBarPolicy)
void setInputContext (QInputContext *)
void setInteractive (bool allowed)
void setLayout (QLayout *)
void setLayoutDirection (Qt::LayoutDirection direction)
void setLineWidth (int)
void setLocale (const QLocale &locale)
void setMask (const QRegion &)
void setMask (const QBitmap &)
void setMatrix (const QMatrix &matrix, bool combine=false)
void setMaximumHeight (int maxh)
void setMaximumSize (int maxw, int maxh)
void setMaximumSize (const QSize &)
void setMaximumWidth (int maxw)
void setMidLineWidth (int)
void setMinimumHeight (int minh)
void setMinimumSize (const QSize &)
void setMinimumSize (int minw, int minh)
void setMinimumWidth (int minw)
void setMouseTracking (bool enable)
void setOptimizationFlag (OptimizationFlag flag, bool enabled=true)
void setOptimizationFlags (OptimizationFlags flags)
void setPalette (const QPalette &)
void setParent (QWidget *parent)
void setParent (QWidget *parent, Qt::WindowFlags f)
void setRenderHint (QPainter::RenderHint hint, bool enabled=true)
void setRenderHints (QPainter::RenderHints hints)
void setResizeAnchor (ViewportAnchor anchor)
void setRubberBandSelectionMode (Qt::ItemSelectionMode mode)
void setScene (QGraphicsScene *scene)
void setSceneRect (const QRectF &rect)
void setSceneRect (qreal x, qreal y, qreal w, qreal h)
void setShortcutAutoRepeat (int id, bool enable=true)
void setShortcutEnabled (int id, bool enable=true)
void setSizeIncrement (int w, int h)
void setSizeIncrement (const QSize &)
void setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
void setSizePolicy (QSizePolicy)
void setStatusTip (const QString &)
void setStyle (QStyle *)
void setToolTip (const QString &)
void setTransform (const QTransform &matrix, bool combine=false)
void setTransformationAnchor (ViewportAnchor anchor)
void setUpdatesEnabled (bool enable)
void setVerticalScrollBar (QScrollBar *scrollbar)
void setVerticalScrollBarPolicy (Qt::ScrollBarPolicy)
void setViewport (QWidget *widget)
void setViewportUpdateMode (ViewportUpdateMode mode)
void setWhatsThis (const QString &)
void setWindowFilePath (const QString &filePath)
void setWindowFlags (Qt::WindowFlags type)
void setWindowIcon (const QIcon &icon)
void setWindowIconText (const QString &)
void setWindowModality (Qt::WindowModality windowModality)
void setWindowOpacity (qreal level)
void setWindowRole (const QString &)
void setWindowState (Qt::WindowStates state)
void setWindowSurface (QWindowSurface *surface)
void shear (qreal sh, qreal sv)
QSize size () const
QSize sizeHint () const
QSize sizeIncrement () const
QSizePolicy sizePolicy () const
void stackUnder (QWidget *)
QString statusTip () const
QStylestyle () const
QString styleSheet () const
bool testAttribute (Qt::WidgetAttribute) const
QString toolTip () const
QWidgettopLevelWidget () const
QTransform transform () const
ViewportAnchor transformationAnchor () const
void translate (qreal dx, qreal dy)
bool underMouse () const
void unsetCursor ()
void unsetLayoutDirection ()
void unsetLocale ()
void update (const QRegion &)
void update (const QRect &)
void update (int x, int y, int w, int h)
void updateGeometry ()
bool updatesEnabled () const
QScrollBarverticalScrollBar () const
Qt::ScrollBarPolicy verticalScrollBarPolicy () const
QWidgetviewport () const
QTransform viewportTransform () const
ViewportUpdateMode viewportUpdateMode () const
QRegion visibleRegion () const
QString whatsThis () const
int width () const
int widthMM () const
QWidgetwindow () const
QString windowFilePath () const
Qt::WindowFlags windowFlags () const
QIcon windowIcon () const
QString windowIconText () const
Qt::WindowModality windowModality () const
qreal windowOpacity () const
QString windowRole () const
Qt::WindowStates windowState () const
QWindowSurfacewindowSurface () const
QString windowTitle () const
Qt::WindowType windowType () const
WId winId () const
int x () const
int y () const
 ~QGraphicsView ()

Static Public Member Functions

static QWidgetfind (WId)
static QWidgetkeyboardGrabber ()
static QWidgetmouseGrabber ()
static void setTabOrder (QWidget *, QWidget *)

Protected Slots

void setupViewport (QWidget *widget)
void updateMicroFocus ()

Protected Member Functions

virtual void actionEvent (QActionEvent *)
void changeEvent (QEvent *)
virtual void closeEvent (QCloseEvent *)
void contextMenuEvent (QContextMenuEvent *event)
void create (WId=0, bool initializeWindow=true, bool destroyOldWindow=true)
void destroy (bool destroyWindow=true, bool destroySubWindows=true)
void dragEnterEvent (QDragEnterEvent *event)
void dragLeaveEvent (QDragLeaveEvent *event)
void dragMoveEvent (QDragMoveEvent *event)
virtual void drawBackground (QPainter *painter, const QRectF &rect)
virtual void drawForeground (QPainter *painter, const QRectF &rect)
void drawFrame (QPainter *)
virtual void drawItems (QPainter *painter, int numItems, QGraphicsItem *items[], const QStyleOptionGraphicsItem options[])
void dropEvent (QDropEvent *event)
virtual void enabledChange (bool)
virtual void enterEvent (QEvent *)
bool event (QEvent *event)
void focusInEvent (QFocusEvent *event)
bool focusNextChild ()
bool focusNextPrevChild (bool next)
void focusOutEvent (QFocusEvent *event)
bool focusPreviousChild ()
virtual void fontChange (const QFont &)
virtual void hideEvent (QHideEvent *)
void inputMethodEvent (QInputMethodEvent *event)
void keyPressEvent (QKeyEvent *event)
void keyReleaseEvent (QKeyEvent *event)
virtual void languageChange ()
virtual void leaveEvent (QEvent *)
int metric (PaintDeviceMetric) const
void mouseDoubleClickEvent (QMouseEvent *event)
void mouseMoveEvent (QMouseEvent *event)
void mousePressEvent (QMouseEvent *event)
void mouseReleaseEvent (QMouseEvent *event)
virtual void moveEvent (QMoveEvent *)
void paintEvent (QPaintEvent *event)
virtual void paletteChange (const QPalette &)
 QGraphicsView (QGraphicsViewPrivate &, QWidget *parent=0)
void resetInputContext ()
void resizeEvent (QResizeEvent *event)
void scrollContentsBy (int dx, int dy)
void setViewportMargins (int left, int top, int right, int bottom)
void showEvent (QShowEvent *event)
virtual void styleChange (QStyle &)
virtual void tabletEvent (QTabletEvent *)
bool viewportEvent (QEvent *event)
void wheelEvent (QWheelEvent *event)
virtual void windowActivationChange (bool)

Protected Attributes

ushort painters

Properties

bool acceptDrops
 whether drop events are enabled for this widget
QString accessibleDescription
 the widget's description as seen by assistive technologies
QString accessibleName
 the widget's name as seen by assistive technologies
Qt::Alignment alignment
 the alignment of the scene in the view when the whole scene is visible.
bool autoFillBackground
 whether the widget background is filled automatically
QBrush backgroundBrush
 the background brush of the scene.
QSize baseSize
 the base size of the widget
CacheMode cacheMode
 which parts of the view are cached
QRect childrenRect
 the bounding rectangle of the widget's children
QRegion childrenRegion
 the combined region occupied by the widget's children
Qt::ContextMenuPolicy contextMenuPolicy
 how the widget shows a context menu
QCursor cursor
 the cursor shape for this widget
DragMode dragMode
 the behavior for dragging the mouse over the scene while the left mouse button is pressed.
bool enabled
 whether the widget is enabled
bool focus
 whether this widget (or its focus proxy) has the keyboard input focus
Qt::FocusPolicy focusPolicy
 the way the widget accepts keyboard focus
QFont font
 the font currently set for the widget
QBrush foregroundBrush
 the foreground brush of the scene.
QRect frameGeometry
 geometry of the widget relative to its parent including any window frame
QRect frameRect
 the frame's rectangle
Shadow frameShadow
 the frame shadow value from the frame style
Shape frameShape
 the frame shape value from the frame style
QSize frameSize
 the size of the widget including any window frame
int frameWidth
 the width of the frame that is drawn.
bool fullScreen
 whether the widget is shown in full screen mode
QRect geometry
 the geometry of the widget relative to its parent and excluding the window frame
int height
 the height of the widget excluding any window frame
Qt::ScrollBarPolicy horizontalScrollBarPolicy
 the policy for the horizontal scroll bar
bool interactive
 whether the view allowed scene interaction.
bool isActiveWindow
 whether this widget's window is the active window
Qt::LayoutDirection layoutDirection
 the layout direction for this widget
int lineWidth
 the line width
QLocale locale
 the widget's locale
bool maximized
 whether this widget is maximized
int maximumHeight
 the widget's maximum height in pixels
QSize maximumSize
 the widget's maximum size in pixels
int maximumWidth
 the widget's maximum width in pixels
int midLineWidth
 the width of the mid-line
bool minimized
 whether this widget is minimized (iconified)
int minimumHeight
 the widget's minimum height in pixels
QSize minimumSize
 the widget's minimum size
QSize minimumSizeHint
 the recommended minimum size for the widget
int minimumWidth
 the widget's minimum width in pixels
bool modal
 whether the widget is a modal widget
bool mouseTracking
 whether mouse tracking is enabled for the widget
QRect normalGeometry
 the geometry of the widget as it will appear when shown as a normal (not maximized or full screen) top-level widget
OptimizationFlags optimizationFlags
 flags that can be used to tune QGraphicsView's performance.
QPalette palette
 the widget's palette
QPoint pos
 the position of the widget within its parent widget
QRect rect
 the internal geometry of the widget excluding any window frame
QPainter::RenderHints renderHints
 the default render hints for the view
ViewportAnchor resizeAnchor
 how the view should position the scene when the view is resized.
Qt::ItemSelectionMode rubberBandSelectionMode
 the behavior for selecting items with a rubber band selection rectangle.
QRectF sceneRect
 the area of the scene visualized by this view.
QSize size
 the size of the widget excluding any window frame
QSize sizeHint
 the recommended size for the widget
QSize sizeIncrement
 the size increment of the widget
QSizePolicy sizePolicy
 the default layout behavior of the widget
QString statusTip
 the widget's status tip
QString styleSheet
 the widget's style sheet
QString toolTip
 the widget's tooltip
ViewportAnchor transformationAnchor
 how the view should position the scene during transformations.
bool updatesEnabled
 whether updates are enabled
Qt::ScrollBarPolicy verticalScrollBarPolicy
 the policy for the vertical scroll bar
ViewportUpdateMode viewportUpdateMode
 how the viewport should update its contents.
bool visible
 whether the widget is visible
QString whatsThis
 the widget's What's This help text.
int width
 the width of the widget excluding any window frame
QString windowFilePath
 the file path associated with a widget
QIcon windowIcon
 the widget's icon
QString windowIconText
 the widget's icon text
Qt::WindowModality windowModality
 which windows are blocked by the modal widget
bool windowModified
 whether the document shown in the window has unsaved changes
double windowOpacity
 The level of opacity for the window.
QString windowTitle
 the window title (caption)
int x
 the x coordinate of the widget relative to its parent including any window frame
int y
 the y coordinate of the widget relative to its parent and including any window frame

Private Member Functions

void _q_unsetViewportCursor ()) Q_PRIVATE_SLOT(d_func()
void void _q_updateLaterSlot ()) friend class QGraphicsSceneWidget
 Q_PRIVATE_SLOT (d_func(), void _q_setViewportCursor(const QCursor &)) Q_PRIVATE_SLOT(d_func()

Friends

class QGraphicsScene
class QGraphicsScenePrivate

Related Functions

(Note that these are not member functions.)


 QT_END_NAMESPACEWId
const Q_GUI_EXPORT QX11Infoqt_x11Info (const QPaintDevice *pd)
 QWidgetList

Detailed Description

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

Since:
4.2

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:

doc/src/snippets/code/src_gui_graphicsview_qgraphicsview.cpp 0

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.

graphicsview-view.png

See also:
QGraphicsScene, QGraphicsItem, QGraphicsSceneEvent

Definition at line 64 of file qgraphicsview.h.


The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index