Rendering

QQuickWindow uses a scene graph to represent what needs to be rendered. This scene graph is disconnected from the QML scene and potentially lives in another thread, depending on the platform implementation. Since the rendering scene graph lives independently from the QML scene, it can also be completely released without affecting the state of the QML scene.

The sceneGraphInitialized() signal is emitted on the rendering thread before the QML scene is rendered to the screen for the first time. If the rendering scene graph has been released, the signal will be emitted again before the next frame is rendered.

Exposure and Visibility

When a QQuickWindow instance is deliberately hidden with hide() or setVisible(false), it will stop rendering and its scene graph and graphics context might be released. The sceneGraphInvalidated() signal will be emitted when this happens.

Warning: It is crucial that graphics operations and interaction with the scene graph happens exclusively on the rendering thread, primarily during the updatePaintNode() phase.

Warning: As signals related to rendering might be emitted from the rendering thread, connections should be made using Qt::DirectConnection.

Resource Management

QML will try to cache images and scene graph nodes to improve performance, but in some low-memory scenarios it might be required to aggressively release these resources. The releaseResources() can be used to force the clean up of certain resources. Calling releaseResources() may result in the entire scene graph and in the case of the OpenGL adaptation the associated context will be deleted. The sceneGraphInvalidated() signal will be emitted when this happens.

Note: All classes with QSG prefix should be used solely on the scene graph's rendering thread. See Scene Graph and Rendering for more information.

Context and Surface Formats

While it is possible to specify a QSurfaceFormat for every QQuickWindow by calling the member function setFormat(), windows may also be created from QML by using the Window and ApplicationWindow elements. In this case there is no C++ code involved in the creation of the window instance, yet applications may still wish to set certain surface format values, for example to request a given OpenGL version or profile. Such applications can call the static function QSurfaceFormat::setDefaultFormat() at startup. The specified format will be used for all Quick windows created afterwards.

enum QQuickWindow::SceneGraphError

graphics context creation failed. This typically means that no suitable OpenGL implementation was found, for example because no graphics drivers are installed and so no OpenGL 2 support is present. On mobile and embedded boards that use OpenGL ES such an error is likely to indicate issues in the windowing system integration and possibly an incorrect configuration of Qt.

This enum was introduced or modified in Qt 5.3.

enum QQuickWindow::TextRenderType

Select NativeTextRendering if you prefer text to look native on the target platform and do not require advanced features such as transformation of the text. Using such features in combination with the NativeTextRendering render type will lend poor and sometimes pixelated results.

[virtual] QQuickWindow::~QQuickWindow()

Returns an accessibility interface for this window, or 0 if such an interface cannot be created.

[signal] void QQuickWindow::afterAnimating()

This signal is emitted on the gui thread before requesting the render thread to perform the synchronization of the scene graph.

Unlike the other similar signals, this one is emitted on the gui thread instead of the render thread. It can be used to synchronize external animation systems with the QML content.

This function was introduced in Qt 5.3.

[signal] void QQuickWindow::afterRendering()

This signal is emitted after the scene has completed rendering, before swapbuffers is called.

This signal can be used to paint using raw OpenGL on top of QML content, or to do screen scraping of the current frame buffer.

The OpenGL context used for rendering the scene graph will be bound at this point.

Warning: This signal is emitted from the scene graph rendering thread. If your slot function needs to finish before execution continues, you must make sure that the connection is direct (see Qt::ConnectionType).

Warning: Make very sure that a signal handler for afterRendering() leaves the OpenGL context in the same state as it was when the signal handler was entered. Failing to do so can result in the scene not rendering properly.

The graphics context used for rendering the scene graph will be bound at this point.

Warning: This signal is emitted from the scene graph rendering thread. If your slot function needs to finish before execution continues, you must make sure that the connection is direct (see Qt::ConnectionType).

Warning: When using the OpenGL adaptation, make sure that a signal handler for afterSynchronizing leaves the OpenGL context in the same state as it was when the signal handler was entered. Failing to do so can result in the scene not rendering properly.

[signal] void QQuickWindow::beforeRendering()

Combined with the modes for clearing the background, this option can be used to paint using raw OpenGL under QML content.

The OpenGL context used for rendering the scene graph will be bound at this point.

Warning: This signal is emitted from the scene graph rendering thread. If your slot function needs to finish before execution continues, you must make sure that the connection is direct (see Qt::ConnectionType).

Warning: Make very sure that a signal handler for beforeRendering leaves the OpenGL context in the same state as it was when the signal handler was entered. Failing to do so can result in the scene not rendering properly.

[signal] void QQuickWindow::beforeSynchronizing()

The OpenGL context used for rendering the scene graph will be bound at this point.

Warning: This signal is emitted from the scene graph rendering thread. If your slot function needs to finish before execution continues, you must make sure that the connection is direct (see Qt::ConnectionType).

Warning: Make very sure that a signal handler for beforeSynchronizing leaves the GL context in the same state as it was when the signal handler was entered. Failing to do so can result in the scene not rendering properly.

When options contains TextureIsOpaque, the engine will create an RGB texture which returns false for QSGTexture::hasAlphaChannel(). Opaque textures will in most cases be faster to render. When this flag is not set, the texture will have an alpha channel based on the image's format.

When options contains TextureHasMipmaps, the engine will create a texture which can use mipmap filtering. Mipmapped textures can not be in an atlas.

When using the OpenGL adaptation, the returned texture will be using GL_TEXTURE_2D as texture target and GL_RGBA as internal format. Reimplement QSGTexture to create textures with different parameters.

Warning: This function will return 0 if the scene graph has not yet been initialized.

Warning: The returned texture is not memory managed by the scene graph and must be explicitly deleted by the caller on the rendering thread. This is achieved by deleting the texture from a QSGNode destructor or by using deleteLater() in the case where the texture already has affinity to the rendering thread.

This is different from QWindow::devicePixelRatio() in that it supports redirected rendering via QQuickRenderControl. When using a QQuickRenderControl, the QQuickWindow is often not created, meaning it is never shown and there is no underlying native window created in the windowing system. As a result, querying properties like the device pixel ratio cannot give correct results. Use this function instead.

It is possible to call the grabWindow() function when the window is not visible. This requires that the window is created and has a valid size and that no other QQuickWindow instances are rendering in the same process.

[virtual protected] void QQuickWindow::hideEvent(QHideEvent *)

Returns an incubation controller that splices incubation between frames for this window. QQuickView automatically installs this controller for you, otherwise you will need to install it yourself using QQmlEngine::setIncubationController().

The controller is owned by the window and will be destroyed when the window is deleted.

bool QQuickWindow::isPersistentOpenGLContext() const

Returns whether the OpenGL context can be released during the lifetime of the QQuickWindow.

Note: This is a hint. When and how this happens is implementation specific. It also only has an effect when using the default OpenGL scene graph adaptation

bool QQuickWindow::isPersistentSceneGraph() const

Returns whether the scene graph nodes and resources can be released during the lifetime of this QQuickWindow.

Note: This is a hint. When and how this happens is implementation specific.

bool QQuickWindow::isSceneGraphInitialized() const

Returns true if the scene graph has been initialized; otherwise returns false.

This signal is emitted on the gui thread when the OpenGL context for this window is created, before it is made current.

Some implementations will share the same OpenGL context between multiple QQuickWindow instances. The openglContextCreated() signal will in this case only be emitted for the first window, when the OpenGL context is actually created.

QQuickWindow::openglContext() will still return 0 for this window until after the QQuickWindow::sceneGraphInitialize() has been emitted.

Note: This signal will only be emmited when using the default OpenGL scene graph adaptation.

This function was introduced in Qt 5.3.

[slot] void QQuickWindow::releaseResources()

This function tries to release redundant resources currently held by the QML scene.

Calling this function might result in the scene graph and the OpenGL context used for rendering being released to release graphics memory. If this happens, the sceneGraphInvalidated() signal will be called, allowing users to clean up their own graphics resources. The setPersistentOpenGLContext() and setPersistentSceneGraph() functions can be used to prevent this from happening, if handling the cleanup is not feasible in the application, at the cost of higher memory usage.

Note: The ownership of the returned pointer stays with Qt. The returned instance may or may not be shared between different QQuickWindow instances, depending on the scenegraph backend in use. Therefore applications are expected to query the interface object for each QQuickWindow instead of reusing the already queried pointer.

void QQuickWindow::resetOpenGLState()

Call this function to reset the OpenGL context its default state.

The scene graph uses the OpenGL context and will both rely on and clobber its state. When mixing raw OpenGL commands with scene graph rendering, this function provides a convenient way of resetting the OpenGL context state back to its default values.

This function does not touch state in the fixed-function pipeline.

This function does not clear the color, depth and stencil buffers. Use QQuickWindow::setClearBeforeRendering to control clearing of the color buffer. The depth and stencil buffer might be clobbered by the scene graph renderer. Clear these manually on demand.

Note: This function only has an effect when using the default OpenGL scene graph adaptation.

[signal] void QQuickWindow::sceneGraphAboutToStop()

This signal is emitted on the render thread when the scene graph is about to stop rendering. This happens usually because the window has been hidden.

Applications may use this signal to release resources, but should be prepared to reinstantiated them again fast. The scene graph and the graphics context are not released at this time.

Warning: This signal is emitted from the scene graph rendering thread. If your slot function needs to finish before execution continues, you must make sure that the connection is direct (see Qt::ConnectionType).

Warning: Make very sure that a signal handler for sceneGraphAboutToStop() leaves the graphics context in the same state as it was when the signal handler was entered. Failing to do so can result in the scene not rendering properly.

This signal is emitted when an error occurred during scene graph initialization.

Applications should connect to this signal if they wish to handle errors, like graphics 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.

This function was introduced in Qt 5.3.

[signal] void QQuickWindow::sceneGraphInitialized()

This signal is emitted when the scene graph has been initialized.

This signal will be emitted from the scene graph rendering thread.

[signal] void QQuickWindow::sceneGraphInvalidated()

This signal is emitted when the scene graph has been invalidated.

This signal implies that the graphics rendering context used has been invalidated and all user resources tied to that context should be released.

In the case of the default OpenGL adaptation the context of this window will be bound when this function is called. The only exception is if the native OpenGL has been destroyed outside Qt's control, for instance through EGL_CONTEXT_LOST.

Schedules job to run when the rendering of this window reaches the given stage.

This is a convenience to the equivalent signals in QQuickWindow for "one shot" tasks.

The window takes ownership over job and will delete it when the job is completed.

If rendering is shut down before job has a chance to run, the job will be run and then deleted as part of the scene graph cleanup. If the window is never shown and no rendering happens before the QQuickWindow is destroyed, all pending jobs will be destroyed without their run() method being called.

If the rendering is happening on a different thread, then the job will happen on the rendering thread.

If stage is NoStage, job will be run at the earliest opportunity whenever the render thread is not busy rendering a frame. If there is no OpenGL context available or the window is not exposed at the time the job is either posted or handled, it is deleted without executing the run() method. If a non-threaded renderer is in use, the run() method of the job is executed synchronously. The OpenGL context is changed to the renderer context before executing a NoStage job.

Note: This function does not trigger rendering; the jobs targeting any other stage than NoStage will be stored run until rendering is triggered elsewhere. To force the job to run earlier, call QQuickWindow::update();

Sets the render target for this window to be an FBO with fboId and size.

The specified FBO must be created in the context of the window or one that shares with it.

Note: fboId can also be set to 0. In this case rendering will target the default framebuffer of whichever surface is current when the scenegraph renders. size must still be valid, specifying the dimensions of the surface.

Note: This function only has an effect when using the default OpenGL scene graph adaptation.

Warning: This function can only be called from the thread doing the rendering.

Requests the specified Qt Quick scenegraph backend. Backends can either be built-in or be installed in form of dynamically loaded plugins.

This is an overloaded function.

Note: The call to the function must happen before constructing the first QQuickWindow in the application. It cannot be changed afterwards.

If backend is invalid or an error occurs, the default backend (OpenGL or software, depending on the Qt configuration) is used.

Note: Calling this function is equivalent to setting the QT_QUICK_BACKEND or QMLSCENE_DEVICE environment variables. However, this API is safer to use in applications that spawn other processes as there is no need to worry about environment inheritance.