QQuickView¶
The
QQuickView
class provides a window for displaying a Qt Quick user interface. More…
Synopsis¶
Functions¶
def
engine
()def
errors
()def
initialSize
()def
resizeMode
()def
rootContext
()def
rootObject
()def
setResizeMode
(arg__1)def
sizeHint
()def
source
()def
status
()
Slots¶
def
setContent
(url, component, item)def
setSource
(arg__1)
Signals¶
def
statusChanged
(arg__1)
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 usingQQmlComponent
and place them in a manually setupQQuickWindow
.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 viewTo receive errors related to loading and executing QML with
QQuickView
, you can connect to thestatusChanged()
signal and monitor forError
. The errors are available viaerrors()
.
QQuickView
also manages sizing of the view and root object. By default, theresizeMode
isSizeViewToRootObject
, which will load the component and resize it to the size of the view. Alternatively theresizeMode
may be set toSizeRootObjectToView
which will resize the view to the size of the root object.See also
Exposing Attributes of C++ Types to QML
QQuickWidget
-
class
QQuickView
(engine, parent)¶ QQuickView([parent=None])
QQuickView(source, renderControl)
QQuickView(source[, parent=None])
- param parent
QWindow
- param source
QUrl
- param renderControl
- param engine
QQmlEngine
Constructs a
QQuickView
with the given QMLengine
andparent
.Note: In this case, the
QQuickView
does not own the givenengine
object; it is the caller’s responsibility to destroy the engine. If theengine
is deleted before the view,status()
will returnError
.Constructs a
QQuickView
with the givenparent
. The default value ofparent
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
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
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
See also
-
PySide2.QtQuick.QQuickView.
rootContext
()¶ - Return type
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 theQQmlEngine
.
-
PySide2.QtQuick.QQuickView.
setContent
(url, component, item)¶ - Parameters
url –
QUrl
component –
QQmlComponent
item –
QObject
Set the source
url
,component
and contentitem
(root of the QML object hierarchy) directly.
-
PySide2.QtQuick.QQuickView.
setResizeMode
(arg__1)¶ - Parameters
arg__1 –
ResizeMode
See also
-
PySide2.QtQuick.QQuickView.
setSource
(arg__1)¶ - Parameters
arg__1 –
QUrl
Sets the source to the
url
, loads the QML component and instantiates it.Ensure that the URL provided is full and correct, in particular, use
fromLocalFile()
when loading a file from the local filesystem.Calling this method multiple times with the same url will result in the QML component being reinstantiated.
See also
-
PySide2.QtQuick.QQuickView.
sizeHint
()¶ - Return type
QSize
Preferred size follows the root object geometry.
-
PySide2.QtQuick.QQuickView.
source
()¶ - Return type
QUrl
Returns the source URL, if set.
See also
© 2018 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.