|  | Home · All Classes · Modules

# QDeclarativeView Class Reference
[QtDeclarative module]

The QDeclarativeView class provides a widget for displaying a Qt Declarative user interface. More...

Inherits QGraphicsView.

### Types

- enum ResizeMode { SizeViewToRootObject, SizeRootObjectToView }
- enum Status { Null, Ready, Loading, Error }

### Methods

- __init__ (self, QWidget parent = None)
- __init__ (self, QUrl source, QWidget parent = None)
- QDeclarativeEngine engine (self)
- list-of-QDeclarativeError errors (self)
- bool eventFilter (self, QObject watched, QEvent e)
- QSize initialSize (self)
- paintEvent (self, QPaintEvent event)
- resizeEvent (self, QResizeEvent)
- ResizeMode resizeMode (self)
- QDeclarativeContext rootContext (self)
- QGraphicsObject rootObject (self)
- setResizeMode (self, ResizeMode)
- setSource (self, QUrl)
- QSize sizeHint (self)
- QUrl source (self)
- Status status (self)
- timerEvent (self, QTimerEvent)

### Qt Signals

- void sceneResized (QSize)
- void statusChanged (QDeclarativeView::Status)

## Detailed Description

The QDeclarativeView class provides a widget for displaying a Qt Declarative user interface.

QDeclarativeItem objects can be placed on a standard QGraphicsScene and displayed with QGraphicsView. QDeclarativeView is a QGraphicsView subclass provided as a convenience for displaying QML files, and connecting between QML and C++ Qt objects.

QDeclarativeView provides:

- Management of QDeclarativeComponent loading and object creation
- Initialization of QGraphicsView for optimal performance with QML using these settings:
  - QGraphicsView.setOptimizationFlags(QGraphicsView.DontSavePainterState)
  - QGraphicsView.setViewportUpdateMode(QGraphicsView.BoundingRectViewportUpdate)
  - QGraphicsScene.setItemIndexMethod(QGraphicsScene.NoIndex)
- Initialization of QGraphicsView for QML key handling using these settings:
  - QGraphicsView.viewport()->setFocusPolicy(Qt.NoFocus)
  - QGraphicsView.setFocusPolicy(Qt.StrongFocus)
  - QGraphicsScene.setStickyFocus(true)

Typical usage:

     QDeclarativeView *view = new QDeclarativeView;
     view->setSource(QUrl.fromLocalFile("myqmlfile.qml"));
     view->show();

Since QDeclarativeView is a QWidget-based class, it can be used to display QML interfaces within QWidget-based GUI applications that do not use the Graphics View framework.

To receive errors related to loading and executing QML with QDeclarativeView, you can connect to the statusChanged() signal and monitor for QDeclarativeView.Error. The errors are available via QDeclarativeView.errors().

## Type Documentation

### QDeclarativeView.ResizeMode

This enum specifies how to resize the view.

Constant | Value | Description
--- | --- | ---
`QDeclarativeView.SizeViewToRootObject` | `0` | The view resizes with the root item in the QML.
`QDeclarativeView.SizeRootObjectToView` | `1` | The view will automatically resize the root item to the size of the view.

### QDeclarativeView.Status

Specifies the loading status of the QDeclarativeView.

Constant | Value | Description
--- | --- | ---
`QDeclarativeView.Null` | `0` | This QDeclarativeView has no source set.
`QDeclarativeView.Ready` | `1` | This QDeclarativeView has loaded and created the QML component.
`QDeclarativeView.Loading` | `2` | This QDeclarativeView is loading network data.
`QDeclarativeView.Error` | `3` | One or more errors has occurred. Call errors() to retrieve a list of errors.

## Method Documentation

### QDeclarativeView.__init__ (self, QWidget parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a QDeclarativeView with the given parent.

### QDeclarativeView.__init__ (self, QUrl source, QWidget parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a QDeclarativeView with the given QML source and parent.

### QDeclarativeEngine QDeclarativeView.engine (self)

Returns a pointer to the QDeclarativeEngine used for instantiating QML Components.

### list-of-QDeclarativeError QDeclarativeView.errors (self)

Return the list of errors that occurred during the last compile or create operation. When the status is not Error, an empty list is returned.

### bool QDeclarativeView.eventFilter (self, QObject watched, QEvent e)

### QSize QDeclarativeView.initialSize (self)

Returns the initial size of the root object

### QDeclarativeView.paintEvent (self, QPaintEvent event)

### QDeclarativeView.resizeEvent (self, QResizeEvent)

### ResizeMode QDeclarativeView.resizeMode (self)

### QDeclarativeContext QDeclarativeView.rootContext (self)

This function returns the root of the context hierarchy. Each QML component is instantiated in a QDeclarativeContext. QDeclarativeContext's are essential for passing data to QML components. In QML, contexts are arranged hierarchically and this hierarchy is managed by the QDeclarativeEngine.

### QGraphicsObject QDeclarativeView.rootObject (self)

Returns the view's root item.

### QDeclarativeView.setResizeMode (self, ResizeMode)

### QDeclarativeView.setSource (self, QUrl)

### QSize QDeclarativeView.sizeHint (self)

### QUrl QDeclarativeView.source (self)

### Status QDeclarativeView.status (self)

### QDeclarativeView.timerEvent (self, QTimerEvent)

## Qt Signal Documentation

### void sceneResized (QSize)

This is the default overload of this signal.

This signal is emitted when the view is resized to size.

### void statusChanged (QDeclarativeView::Status)

This is the default overload of this signal.

This signal is emitted when the component's current status changes.