PySide6.QtQuick.QQuickView¶
- class QQuickView¶
The
QQuickView
class provides a window for displaying a Qt Quick user interface. More…Synopsis¶
Properties¶
resizeModeᅟ
- Whether the view should resize the window contentssourceᅟ
- URL of the source of the QML component
Methods¶
def
__init__()
def
engine()
def
errors()
def
initialSize()
def
resizeMode()
def
rootContext()
def
rootObject()
def
setResizeMode()
def
sizeHint()
def
source()
def
status()
Slots¶
def
loadFromModule()
def
setContent()
def
setSource()
Signals¶
def
statusChanged()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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 setupQQuickWindow
.Typical usage:
if __name__ == "__main__": app = QGuiApplication(argc, argv) view = QQuickView() view.setSource(QUrl.fromLocalFile("myqmlfile.qml")) view.show() sys.exit(app.exec())
To 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
- class 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.
- class 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.
Note
Properties can be used directly when
from __feature__ import true_property
is used or via accessor functions otherwise.- property resizeModeᅟ: QQuickView.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
- Access functions:
This property holds The URL of the source of the QML component..
Ensure that the URL provided is full and correct, in particular, use QUrl::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.
- Access functions:
- property statusᅟ: QQuickView.Status¶
The component’s current
status
.- Access functions:
Signal
statusChanged()
Constructs a
QQuickView
with the givenparent
. The default value ofparent
is 0.- __init__(engine, parent)
- Parameters:
engine –
QQmlEngine
parent –
QWindow
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
.- __init__(source, renderControl)
- Parameters:
source –
QUrl
renderControl –
QQuickRenderControl
Constructs a
QQuickView
with the given QMLsource
andparent
. The default value ofparent
isnullptr
.- __init__(uri, typeName[, parent=None])
- Parameters:
uri – str
typeName – str
parent –
QWindow
Constructs a
QQuickView
with the element specified byuri
andtypeName
and parentparent
. The default value ofparent
isnullptr
.See also
- engine()¶
- Return type:
Returns a pointer to the QQmlEngine used for instantiating QML Components.
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.
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. initialSize contains the size of the root object before it was resized.- loadFromModule(uri, typeName)¶
- Parameters:
uri – str
typeName – str
Loads the QML component identified by
uri
andtypeName
. If the component is backed by a QML file,source
will be set accordingly. For types defined inC++
,source
will be empty.If any
source
was set before this method was called, it will be cleared.Calling this method multiple times with the same
uri
andtypeName
will result in the QML component being reinstantiated.See also
setSource
loadFromModule
- resizeMode()¶
- Return type:
See also
Getter of property
resizeModeᅟ
.- rootContext()¶
- Return type:
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.
- rootObject()¶
- Return type:
Returns the view’s root
item
.- setContent(url, component, item)¶
- Parameters:
url –
QUrl
component –
QQmlComponent
item –
QObject
- setInitialProperties(initialProperties)¶
- Parameters:
initialProperties – Dictionary with keys of type .QString and values of type QVariant.
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Sets the initial properties
initialProperties
with which the QML component gets initialized after callingsetSource()
.view = { 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 becomeReady
.See also
- setResizeMode(arg__1)¶
- Parameters:
arg__1 –
ResizeMode
See also
Setter of property
resizeModeᅟ
.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 QUrl::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
Setter of property
sourceᅟ
.Returns the source URL, if set.
See also
Getter of property
sourceᅟ
.Getter of property
statusᅟ
.This signal is emitted when the component’s current
status
changes.Notification signal of property
statusᅟ
.