PySide6.QtQuickWidgets.QQuickWidget¶
- class QQuickWidget¶
- The - QQuickWidgetclass provides a widget for displaying a Qt Quick user interface. More…- Synopsis¶- Properties¶- resizeModeᅟ- Determines whether the view should resize the window contents
- sourceᅟ- URL of the source of the QML component
 - Methods¶- def - __init__()
- def - engine()
- def - errors()
- def - format()
- def - initialSize()
- def - quickWindow()
- def - resizeMode()
- def - rootContext()
- def - rootObject()
- def - setClearColor()
- def - setFormat()
- def - setResizeMode()
- def - source()
- def - status()
 - Slots¶- 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¶- This is a convenience wrapper for - QQuickWindowwhich 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 set up- QQuickWidget.- Typical usage: - QQuickWidget *view = new QQuickWidget; view->setSource(QUrl::fromLocalFile("myqmlfile.qml")); view->show(); - To receive errors related to loading and executing QML with - QQuickWidget, you can connect to the- statusChanged()signal and monitor for- Error. The errors are available via- errors().- QQuickWidgetalso manages sizing of the view and root object. By default, the- resizeModeis- SizeViewToRootObject, which will load the component and resize it to the size of the view. Alternatively the- resizeModemay be set to- SizeRootObjectToViewwhich will resize the view to the size of the root object.- Performance Considerations¶- QQuickWidgetis an alternative to using- QQuickViewand QWidget::createWindowContainer(). The restrictions on stacking order do not apply, making- QQuickWidgetthe more flexible alternative, behaving more like an ordinary widget.- However, the above mentioned advantages come at the expense of performance: - Unlike - QQuickWindowand- QQuickView,- QQuickWidgetinvolves at least one additional render pass targeting an offscreen color buffer, typically a 2D texture, followed by drawing a texture quad. This means increased load especially for the fragment processing of the GPU.
- Using - QQuickWidgetdisables the threaded render loop on all platforms. This means that some of the benefits of threaded rendering, for example Animator classes and vsync driven animations, will not be available.
 - Note - Avoid calling winId() on a - QQuickWidget. This function triggers the creation of a native window, resulting in reduced performance and possibly rendering glitches. The entire purpose of- QQuickWidgetis to render Quick scenes without a separate native window, hence making it a native widget should always be avoided.- Graphics API Support¶- QQuickWidgetis functional with all the 3D graphics APIs supported by Qt Quick, as well as the- softwarebackend. Other backends, for example OpenVG, are not compatible however and attempting to construct a- QQuickWidgetwill lead to problems.- Overriding the platform’s default graphics API is done the same way as with - QQuickWindowand- QQuickView: either by calling- setGraphicsApi()early on before constructing the first- QQuickWidget, or by setting the- QSG_RHI_BACKENDenvironment variable.- Note - One top-level window can only use one single graphics API for rendering. For example, attempting to place a - QQuickWidgetusing Vulkan and a QOpenGLWidget in the widget hierarchy of the same top-level window, problems will occur and one of the widgets will not be rendering as expected.- Scene Graph and Context Persistency¶- QQuickWidgethonors- isPersistentSceneGraph(), meaning that applications can decide - by calling- setPersistentSceneGraph()on the window returned from the- quickWindow()function - to let scenegraph nodes and other Qt Quick scene related resources be released whenever the widget becomes hidden. By default persistency is enabled, just like with- QQuickWindow.- When running with the OpenGL, - QQuickWindowoffers the possibility to disable persistent OpenGL contexts as well. This setting is currently ignored by- QQuickWidgetand the context is always persistent. The OpenGL context is thus not destroyed when hiding the widget. The context is destroyed only when the widget is destroyed or when the widget gets reparented into another top-level widget’s child hierarchy. However, some applications, in particular those that have their own graphics resources due to performing custom OpenGL rendering in the Qt Quick scene, may wish to disable the latter since they may not be prepared to handle the loss of the context when moving a- QQuickWidgetinto another window. Such applications can set the QCoreApplication::AA_ShareOpenGLContexts attribute. For a discussion on the details of resource initialization and cleanup, refer to the QOpenGLWidget documentation.- Note - QQuickWidgetoffers less fine-grained control over its internal OpenGL context than QOpenGLWidget, and there are subtle differences, most notably that disabling the persistent scene graph will lead to destroying the context on a window change regardless of the presence of QCoreApplication::AA_ShareOpenGLContexts.- Limitations¶- Putting other widgets underneath and making the - QQuickWidgettransparent will not lead to the expected results: the widgets underneath will not be visible. This is because in practice the- QQuickWidgetis drawn before all other regular, non-OpenGL widgets, and so see-through types of solutions are not feasible. Other type of layouts, like having widgets on top of the- QQuickWidget, will function as expected.- When absolutely necessary, this limitation can be overcome by setting the Qt::WA_AlwaysStackOnTop attribute on the - QQuickWidget. Be aware, however that this breaks stacking order. For example it will not be possible to have other widgets on top of the- QQuickWidget, so it should only be used in situations where a semi-transparent- QQuickWidgetwith other widgets visible underneath is required.- This limitation only applies when there are other widgets underneath the - QQuickWidgetinside the same window. Making the window semi-transparent, with other applications and the desktop visible in the background, is done in the traditional way: Set Qt::WA_TranslucentBackground on the top-level window, request an alpha channel, and change the Qt Quick Scenegraph’s clear color to Qt::transparent via- setClearColor().- Tab Key Handling¶- On press of the - [TAB]key, the item inside the- QQuickWidgetgets focus. If this item can handle- [TAB]key press, focus will change accordingly within the item, otherwise the next widget in the focus chain gets focus.- See also - Qt Quick Widgets Example - QQuickView- class ResizeMode¶
- This enum specifies how to resize the view. - Constant - Description - QQuickWidget.SizeViewToRootObject - The view resizes with the root item in the QML. - QQuickWidget.SizeRootObjectToView - The view will automatically resize the root item to the size of the view. 
 - class Status¶
- Specifies the loading status of the - QQuickWidget.- Constant - Description - QQuickWidget.Null - This - QQuickWidgethas no source set.- QQuickWidget.Ready - This - QQuickWidgethas loaded and created the QML component.- QQuickWidget.Loading - This - QQuickWidgetis loading network data.- QQuickWidget.Error - One or more errors occurred. Call - errors()to retrieve a list of errors.
 - Note - Properties can be used directly when - from __feature__ import true_propertyis used or via accessor functions otherwise.- property resizeModeᅟ: QQuickWidget.ResizeMode¶
 - This property Determines 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.- Regardless of this property, the sizeHint of the view is the initial size of the root item. Note though that since QML may load dynamically, that size may change. - 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 - 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ᅟ: QQuickWidget.Status¶
 - The component’s current - status.- Access functions:
- Signal - statusChanged()
 
 - Constructs a - QQuickWidgetwith a default QML engine as a child of- parent.- The default value of - parentis- nullptr.- __init__(engine, parent)
- Parameters:
- engine – - QQmlEngine
- parent – - QWidget
 
 
 - Constructs a - QQuickWidgetwith the given QML- engineas a child of- parent.- Note - The - QQuickWidgetdoes not take ownership of the given- engineobject; it is the caller’s responsibility to destroy the engine. If the- engineis deleted before the view,- status()will return- Error.- Constructs a - QQuickWidgetwith a default QML engine and the given QML- sourceas a child of- parent.- The default value of - parentis- nullptr.- 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.- See also - format()¶
- Return type:
 
 - Returns the actual surface format. - If the widget has not yet been shown, the requested format is returned. - See also - Renders a frame and reads it back into an image. - Note - This is a potentially expensive operation. - Returns the initial size of the root object. - If - resizeModeis- SizeRootObjectToView, the root object will be resized to the size of the view. This function returns the size of the root object before it was resized.- quickWindow()¶
- Return type:
 
 - Returns the offscreen - QQuickWindowwhich is used by this widget to drive the Qt Quick rendering. This is useful if you want to use- QQuickWindowAPIs that are not currently exposed by- QQuickWidget, for instance connecting to the- beforeRendering()signal in order to draw native OpenGL content below Qt Quick’s own rendering.- Warning - Use the return value of this function with caution. In particular, do not ever attempt to show the - QQuickWindow, and be very careful when using other QWindow-only APIs.- Warning - The offscreen window may be deleted (and recreated) during the life time of the - QQuickWidget, particularly when the widget is moved to another- QQuickWindow. If you need to know when the window has been replaced, connect to its destroyed() signal.- 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. Can be null when- setSource()has not been called, if it was called with broken QtQuick code or while the QtQuick contents are being created.- sceneGraphError(error, message)¶
- Parameters:
- error – - SceneGraphError
- message – str 
 
 
 - This signal is emitted when an - erroroccurred during scene graph initialization.- Applications should connect to this signal if they wish to handle errors, like OpenGL context creation failures, in a custom way. When no slot is connected to the signal, the behavior will be different: Quick will print the - message, or show a message box, and terminate the application.- This signal will be emitted from the GUI thread. - See also - Sets the clear - color. By default this is an opaque color.- To get a semi-transparent - QQuickWidget, call this function with- colorset to Qt::transparent, set the Qt::WA_TranslucentBackground widget attribute on the top-level window, and request an alpha channel via- setFormat().- See also - setContent(url, component, item)¶
- Parameters:
- url – - QUrl
- component – - QQmlComponent
- item – - QObject
 
 
 - setFormat(format)¶
- Parameters:
- format – - QSurfaceFormat
 
 - Sets the surface - formatfor the context and offscreen surface used by this widget.- Call this function when there is a need to request a context for a given OpenGL version or profile. The sizes for depth, stencil and alpha buffers are taken care of automatically and there is no need to request those explicitly. - 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 - statuschanges.- Notification signal of property - statusᅟ.