QQuickView

The QQuickView class provides a window for displaying a Qt Quick user interface. More

Inheritance diagram of PySide2.QtQuick.QQuickView

Synopsis

Functions

Slots

Signals

Detailed Description

This is a convenience subclass of QQuickWindow which will automatically load and display a QML scene when given the URL of the main source file. Alternatively, you can instantiate your own objects using QQmlComponent and place them in a manually setup QQuickWindow .

Typical usage:

if __name__ == '__main__':
    app = QGuiApplication(sys.argv)
    view = QQuickView()
    view.setResizeMode(QQuickView.SizeRootObjectToView)

    qmlFile = os.path.join(os.path.dirname(__file__), 'view.qml')
    view.setSource(QUrl.fromLocalFile(os.path.abspath(qmlFile)))
    if view.status() == QQuickView.Error:
        sys.exit(-1)
    view.show()

    app.exec_()
    # Deleting the view before it goes out of scope is required to make
    # sure all child QML instances are destroyed in the correct order.
    del view

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

QQuickView also manages sizing of the view and root object. By default, the resizeMode is SizeViewToRootObject , which will load the component and resize it to the size of the view. Alternatively the resizeMode may be set to SizeRootObjectToView which will resize the view to the size of the root object.

See also

Exposing Attributes of C++ Types to QML QQuickWidget

class PySide2.QtQuick.QQuickView(engine, parent)

PySide2.QtQuick.QQuickView([parent=None])

PySide2.QtQuick.QQuickView(source, renderControl)

PySide2.QtQuick.QQuickView(source[, parent=None])

param parent:

PySide2.QtGui.QWindow

param source:

PySide2.QtCore.QUrl

param renderControl:

PySide2.QtQuick.QQuickRenderControl

param engine:

PySide2.QtQml.QQmlEngine

Constructs a QQuickView with the given QML engine and parent .

Note: In this case, the QQuickView does not own the given engine object; it is the caller’s responsibility to destroy the engine. If the engine is deleted before the view, status() will return Error .

See also

Status status() errors()

Constructs a QQuickView with the given parent . The default value of parent is 0.

PySide2.QtQuick.QQuickView.ResizeMode

This enum specifies how to resize the view.

Constant

Description

QQuickView.SizeViewToRootObject

The view resizes with the root item in the QML.

QQuickView.SizeRootObjectToView

The view will automatically resize the root item to the size of the view.

PySide2.QtQuick.QQuickView.Status

Specifies the loading status of the QQuickView .

Constant

Description

QQuickView.Null

This QQuickView has no source set.

QQuickView.Ready

This QQuickView has loaded and created the QML component.

QQuickView.Loading

This QQuickView is loading network data.

QQuickView.Error

One or more errors has occurred. Call errors() to retrieve a list of errors.

PySide2.QtQuick.QQuickView.engine()
Return type:

PySide2.QtQml.QQmlEngine

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

PySide2.QtQuick.QQuickView.errors()
Return type:

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.

PySide2.QtQuick.QQuickView.initialSize()
Return type:

PySide2.QtCore.QSize

Returns the initial size of the root object.

If resizeMode is QQuickItem::SizeRootObjectToView the root object will be resized to the size of the view. contains the size of the root object before it was resized.

PySide2.QtQuick.QQuickView.resizeMode()
Return type:

ResizeMode

This property holds whether the view should resize the window contents.

If this property is set to SizeViewToRootObject (the default), the view resizes to the size of the root item in the QML.

If this property is set to SizeRootObjectToView , the view will automatically resize the root item to the size of the view.

See also

initialSize()

PySide2.QtQuick.QQuickView.rootContext()
Return type:

PySide2.QtQml.QQmlContext

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

PySide2.QtQuick.QQuickView.rootObject()
Return type:

PySide2.QtQuick.QQuickItem

Returns the view’s root item .

PySide2.QtQuick.QQuickView.setContent(url, component, item)
Parameters:

Set the source url , component and content item (root of the QML object hierarchy) directly.

PySide2.QtQuick.QQuickView.setInitialProperties(initialProperties)
Parameters:

initialProperties

Sets the initial properties initialProperties with which the QML component gets initialized after calling setSource() .

QScopedPointer<QQuickView> view { new QQuickView };
view->setInitialProperties({"x, 100"}, {"width", 50});
view->setSource(QUrl::fromLocalFile("myqmlfile.qml"));
view->show();

Note

You can only use this function to initialize top-level properties.

Note

This function should always be called before setSource , as it has no effect once the component has become Ready .

See also

createWithInitialProperties()

PySide2.QtQuick.QQuickView.setResizeMode(arg__1)
Parameters:

arg__1ResizeMode

This property holds whether the view should resize the window contents.

If this property is set to SizeViewToRootObject (the default), the view resizes to the size of the root item in the QML.

If this property is set to SizeRootObjectToView , the view will automatically resize the root item to the size of the view.

See also

initialSize()

PySide2.QtQuick.QQuickView.setSource(arg__1)
Parameters:

arg__1PySide2.QtCore.QUrl

This property holds The URL of the source of the QML component..

Ensure that the URL provided is full and correct, in particular, use fromLocalFile() when loading a file from the local filesystem.

Note that setting a source URL will result in the QML component being instantiated, even if the URL is unchanged from the current value.

PySide2.QtQuick.QQuickView.sizeHint()
Return type:

PySide2.QtCore.QSize

Preferred size follows the root object geometry.

PySide2.QtQuick.QQuickView.source()
Return type:

PySide2.QtCore.QUrl

This property holds The URL of the source of the QML component..

Ensure that the URL provided is full and correct, in particular, use fromLocalFile() when loading a file from the local filesystem.

Note that setting a source URL will result in the QML component being instantiated, even if the URL is unchanged from the current value.

PySide2.QtQuick.QQuickView.status()
Return type:

Status

The component’s current status .

PySide2.QtQuick.QQuickView.statusChanged(arg__1)
Parameters:

arg__1Status