QQuickWindow

The QQuickWindow class provides the window for displaying a graphical QML scene. More

Inheritance diagram of PySide2.QtQuick.QQuickWindow

Inherited by: QQuickView

Synopsis

Functions

Slots

Static functions

Detailed Description

QQuickWindow provides the graphical scene management needed to interact with and display a scene of QQuickItems.

A QQuickWindow always has a single invisible root item. To add items to this window, reparent the items to the root item or to an existing item in the scene.

For easily displaying a scene from a QML file, see QQuickView .

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.

Integration with OpenGL

When using the default OpenGL adaptation, it is possible to integrate OpenGL calls directly into the QQuickWindow using the same OpenGL context as the Qt Quick Scene Graph. This is done by connecting to the beforeRendering() or afterRendering() signal.

Note

When using beforeRendering() , make sure to disable clearing before rendering with setClearBeforeRendering() .

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 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 setDefaultFormat() at startup. The specified format will be used for all Quick windows created afterwards.

class QQuickWindow(renderControl)

QQuickWindow([parent=None])

param parent

QWindow

param renderControl

QQuickRenderControl

Constructs a window for displaying a QML scene with parent window parent .

PySide2.QtQuick.QQuickWindow.CreateTextureOption

The enums are used to customize a texture is wrapped.

Constant

Description

QQuickWindow.TextureHasAlphaChannel

The texture has an alpha channel and should be drawn using blending.

QQuickWindow.TextureHasMipmaps

The texture has mipmaps and can be drawn with mipmapping enabled.

QQuickWindow.TextureOwnsGLTexture

The texture object owns the texture id and will delete the OpenGL texture when the texture object is deleted.

QQuickWindow.TextureCanUseAtlas

The image can be uploaded into a texture atlas.

QQuickWindow.TextureIsOpaque

The texture will return false for hasAlphaChannel() and will not be blended. This flag was added in Qt 5.6.

PySide2.QtQuick.QQuickWindow.RenderStage

Constant

Description

QQuickWindow.BeforeSynchronizingStage

Before synchronization.

QQuickWindow.AfterSynchronizingStage

After synchronization.

QQuickWindow.BeforeRenderingStage

Before rendering.

QQuickWindow.AfterRenderingStage

After rendering.

QQuickWindow.AfterSwapStage

After the frame is swapped.

QQuickWindow.NoStage

As soon as possible. This value was added in Qt 5.6.

PySide2.QtQuick.QQuickWindow.SceneGraphError

This enum describes the error in a sceneGraphError() signal.

Constant

Description

QQuickWindow.ContextNotAvailable

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.

PySide2.QtQuick.QQuickWindow.TextRenderType

This enum describes the default render type of text-like elements in Qt Quick ( Text , TextInput , etc.).

Select 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 render type will lend poor and sometimes pixelated results.

Constant

Description

QQuickWindow.QtTextRendering

Use Qt’s own rasterization algorithm.

QQuickWindow.NativeTextRendering

Use the operating system’s native rasterizer for text.

New in version 5.10.

PySide2.QtQuick.QQuickWindow.activeFocusItem()
Return type

QQuickItem

PySide2.QtQuick.QQuickWindow.activeFocusItemChanged()
PySide2.QtQuick.QQuickWindow.afterAnimating()
PySide2.QtQuick.QQuickWindow.afterRendering()
PySide2.QtQuick.QQuickWindow.afterSynchronizing()
PySide2.QtQuick.QQuickWindow.beforeRendering()
PySide2.QtQuick.QQuickWindow.beforeSynchronizing()
PySide2.QtQuick.QQuickWindow.clearBeforeRendering()
Return type

bool

Returns whether clearing of the color buffer is done before rendering or not.

PySide2.QtQuick.QQuickWindow.color()
Return type

QColor

See also

setColor()

PySide2.QtQuick.QQuickWindow.colorChanged(arg__1)
Parameters

arg__1QColor

PySide2.QtQuick.QQuickWindow.contentItem()
Return type

QQuickItem

PySide2.QtQuick.QQuickWindow.createTextureFromId(id, size[, options=QQuickWindow.CreateTextureOption()])
Parameters
  • iduint

  • sizeQSize

  • optionsCreateTextureOptions

Return type

QSGTexture

Creates a new QSGTexture object from an existing OpenGL texture id and size .

The caller of the function is responsible for deleting the returned texture.

The returned texture will be using GL_TEXTURE_2D as texture target and assumes that internal format is GL_RGBA . Reimplement QSGTexture to create textures with different parameters.

Use options to customize the texture attributes. The TextureUsesAtlas option is ignored.

Warning

This function will return null if the scenegraph has not yet been initialized or OpenGL is not in use.

Note

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

PySide2.QtQuick.QQuickWindow.createTextureFromImage(image)
Parameters

imageQImage

Return type

QSGTexture

This is an overloaded function.

PySide2.QtQuick.QQuickWindow.createTextureFromImage(image, options)
Parameters
  • imageQImage

  • optionsCreateTextureOptions

Return type

QSGTexture

Creates a new QSGTexture from the supplied image . If the image has an alpha channel, the corresponding texture will have an alpha channel.

The caller of the function is responsible for deleting the returned texture. For example whe using the OpenGL adaptation the actual OpenGL texture will be deleted when the texture object is deleted.

When options contains TextureCanUseAtlas , the engine may put the image into a texture atlas. Textures in an atlas need to rely on normalizedTextureSubRect() for their geometry and will not support Repeat . Other values from CreateTextureOption are ignored.

When options contains TextureIsOpaque , the engine will create an RGB texture which returns false for 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 function can be called from any thread.

PySide2.QtQuick.QQuickWindow.effectiveDevicePixelRatio()
Return type

qreal

Returns the device pixel ratio for this window.

This is different from 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.

See also

devicePixelRatio()

PySide2.QtQuick.QQuickWindow.frameSwapped()
PySide2.QtQuick.QQuickWindow.grabWindow()
Return type

QImage

Grabs the contents of the window and returns it as an image.

It is possible to call the 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.

Warning

Calling this function will cause performance problems.

Warning

This function can only be called from the GUI thread.

static PySide2.QtQuick.QQuickWindow.hasDefaultAlphaBuffer()
Return type

bool

Returns whether to use alpha transparency on newly created windows.

PySide2.QtQuick.QQuickWindow.incubationController()
Return type

QQmlIncubationController

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 setIncubationController() .

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

PySide2.QtQuick.QQuickWindow.isPersistentOpenGLContext()
Return type

bool

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

PySide2.QtQuick.QQuickWindow.isPersistentSceneGraph()
Return type

bool

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.

PySide2.QtQuick.QQuickWindow.isSceneGraphInitialized()
Return type

bool

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

PySide2.QtQuick.QQuickWindow.mouseGrabberItem()
Return type

QQuickItem

Returns the item which currently has the mouse grab.

PySide2.QtQuick.QQuickWindow.openglContext()
Return type

QOpenGLContext

Returns the OpenGL context used for rendering.

If the scene graph is not ready, or the scene graph is not using OpenGL, this function will return null.

Note

If using a scene graph adaptation other than OpenGL this function will return nullptr.

PySide2.QtQuick.QQuickWindow.openglContextCreated(context)
Parameters

contextQOpenGLContext

PySide2.QtQuick.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.

PySide2.QtQuick.QQuickWindow.renderTarget()
Return type

QOpenGLFramebufferObject

Returns the render target for this window.

The default is to render to the surface of the window, in which case the render target is 0.

Note

This function will return nullptr when not using the OpenGL scene graph adaptation.

PySide2.QtQuick.QQuickWindow.renderTargetId()
Return type

uint

Returns the FBO id of the render target when set; otherwise returns 0.

PySide2.QtQuick.QQuickWindow.renderTargetSize()
Return type

QSize

Returns the size of the currently set render target; otherwise returns an empty size.

PySide2.QtQuick.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 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.

PySide2.QtQuick.QQuickWindow.sceneGraphAboutToStop()
static PySide2.QtQuick.QQuickWindow.sceneGraphBackend()
Return type

unicode

Returns the requested Qt Quick scenegraph backend.

Note

The return value of this function may still be outdated by subsequent calls to setSceneGraphBackend() until the first QQuickWindow in the application has been constructed.

PySide2.QtQuick.QQuickWindow.sceneGraphError(error, message)
Parameters
PySide2.QtQuick.QQuickWindow.sceneGraphInitialized()
PySide2.QtQuick.QQuickWindow.sceneGraphInvalidated()
PySide2.QtQuick.QQuickWindow.scheduleRenderJob(job, schedule)
Parameters

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 update() ;

PySide2.QtQuick.QQuickWindow.sendEvent(arg__1, arg__2)
Parameters
Return type

bool

Propagates an event e to a QQuickItem item on the window.

Use sendEvent() directly instead.

The return value is currently not used.

PySide2.QtQuick.QQuickWindow.setClearBeforeRendering(enabled)
Parameters

enabledbool

Sets whether the scene graph rendering of QML should clear the color buffer before it starts rendering to enabled .

By disabling clearing of the color buffer, it is possible to render OpengGL content under the scene graph.

The color buffer is cleared by default.

PySide2.QtQuick.QQuickWindow.setColor(color)
Parameters

colorQColor

See also

color()

static PySide2.QtQuick.QQuickWindow.setDefaultAlphaBuffer(useAlpha)
Parameters

useAlphabool

useAlpha specifies whether to use alpha transparency on newly created windows.

In any application which expects to create translucent windows, it’s necessary to set this to true before creating the first QQuickWindow . The default value is false.

PySide2.QtQuick.QQuickWindow.setPersistentOpenGLContext(persistent)
Parameters

persistentbool

Sets whether the OpenGL context should be preserved, and cannot be released until the last window is deleted, to persistent . The default value is true.

The OpenGL context can be released to free up graphics resources when the window is obscured, hidden or not rendering. When this happens is implementation specific.

The aboutToBeDestroyed() signal is emitted from the openglContext() when the OpenGL context is about to be released. The sceneGraphInitialized() signal is emitted when a new OpenGL context is created for this window. Make a DirectConnection to these signals to be notified.

The OpenGL context is still released when the last QQuickWindow is deleted.

Note

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

PySide2.QtQuick.QQuickWindow.setPersistentSceneGraph(persistent)
Parameters

persistentbool

Sets whether the scene graph nodes and resources can be released to persistent . The default value is true.

The scene graph nodes and resources can be released to free up graphics resources when the window is obscured, hidden or not rendering. When this happens is implementation specific.

The sceneGraphInvalidated() signal is emitted when cleanup occurs. The sceneGraphInitialized() signal is emitted when a new scene graph is recreated for this window. Make a DirectConnection to these signals to be notified.

The scene graph nodes and resources are still released when the last QQuickWindow is deleted.

PySide2.QtQuick.QQuickWindow.setRenderTarget(fboId, size)
Parameters
  • fboIduint

  • sizeQSize

This is an overloaded function.

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.

PySide2.QtQuick.QQuickWindow.setRenderTarget(fbo)
Parameters

fboQOpenGLFramebufferObject

Sets the render target for this window to be fbo .

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

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.

See also

renderTarget()

static PySide2.QtQuick.QQuickWindow.setSceneGraphBackend(backend)
Parameters

backend – unicode

static PySide2.QtQuick.QQuickWindow.setTextRenderType(renderType)
Parameters

renderTypeTextRenderType

Sets the default render type of text-like elements in Qt Quick to renderType .

Note

setting the render type will only affect elements created afterwards; the render type of existing elements will not be modified.

See also

textRenderType()

static PySide2.QtQuick.QQuickWindow.textRenderType()
Return type

TextRenderType

Returns the render type of text-like elements in Qt Quick. The default is QtTextRendering .

PySide2.QtQuick.QQuickWindow.update()

Schedules the window to render another frame.

Calling differs from update() in that it always triggers a repaint, regardless of changes in the underlying scene graph or not.