QQuickWindow¶
The
QQuickWindow
class provides the window for displaying a graphical QML scene. More…
Inherited by: QQuickView
Synopsis¶
Functions¶
def
activeFocusItem
()def
clearBeforeRendering
()def
color
()def
contentItem
()def
createTextureFromId
(id, size[, options=QQuickWindow.CreateTextureOption()])def
createTextureFromImage
(image)def
createTextureFromImage
(image, options)def
effectiveDevicePixelRatio
()def
grabWindow
()def
incubationController
()def
isPersistentOpenGLContext
()def
isPersistentSceneGraph
()def
isSceneGraphInitialized
()def
mouseGrabberItem
()def
openglContext
()def
renderTarget
()def
renderTargetId
()def
renderTargetSize
()def
resetOpenGLState
()def
scheduleRenderJob
(job, schedule)def
sendEvent
(arg__1, arg__2)def
setClearBeforeRendering
(enabled)def
setColor
(color)def
setPersistentOpenGLContext
(persistent)def
setPersistentSceneGraph
(persistent)def
setRenderTarget
(fbo)def
setRenderTarget
(fboId, size)
Slots¶
def
releaseResources
()def
update
()
Signals¶
def
activeFocusItemChanged
()def
afterAnimating
()def
afterRendering
()def
afterSynchronizing
()def
beforeRendering
()def
beforeSynchronizing
()def
colorChanged
(arg__1)def
frameSwapped
()def
openglContextCreated
(context)def
sceneGraphAboutToStop
()def
sceneGraphError
(error, message)def
sceneGraphInitialized
()def
sceneGraphInvalidated
()
Static functions¶
def
hasDefaultAlphaBuffer
()def
sceneGraphBackend
()def
setDefaultAlphaBuffer
(useAlpha)def
setSceneGraphBackend
(backend)def
setTextRenderType
(renderType)def
textRenderType
()
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 thebeforeRendering()
orafterRendering()
signal.Note
When using
beforeRendering()
, make sure to disable clearing before rendering withsetClearBeforeRendering()
.
Exposure and Visibility¶
When a
QQuickWindow
instance is deliberately hidden withhide()
orsetVisible
(false), it will stop rendering and its scene graph and graphics context might be released. ThesceneGraphInvalidated()
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. CallingreleaseResources()
may result in the entire scene graph and in the case of the OpenGL adaptation the associated context will be deleted. ThesceneGraphInvalidated()
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 everyQQuickWindow
by calling the member functionsetFormat()
, 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 functionsetDefaultFormat()
at startup. The specified format will be used for all Quick windows created afterwards.See also
-
class
QQuickWindow
(renderControl)¶ QQuickWindow([parent=None])
- param parent
QWindow
- param renderControl
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.
See also
-
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
-
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.
See also
-
PySide2.QtQuick.QQuickWindow.
color
()¶ - Return type
QColor
See also
-
PySide2.QtQuick.QQuickWindow.
colorChanged
(arg__1)¶ - Parameters
arg__1 –
QColor
-
PySide2.QtQuick.QQuickWindow.
contentItem
()¶ - Return type
-
PySide2.QtQuick.QQuickWindow.
createTextureFromId
(id, size[, options=QQuickWindow.CreateTextureOption()])¶ - Parameters
id –
uint
size –
QSize
options –
CreateTextureOptions
- Return type
Creates a new
QSGTexture
object from an existing OpenGL textureid
andsize
.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 isGL_RGBA
. ReimplementQSGTexture
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.
See also
-
PySide2.QtQuick.QQuickWindow.
createTextureFromImage
(image)¶ - Parameters
image –
QImage
- Return type
This is an overloaded function.
-
PySide2.QtQuick.QQuickWindow.
createTextureFromImage
(image, options) - Parameters
image –
QImage
options –
CreateTextureOptions
- Return type
Creates a new
QSGTexture
from the suppliedimage
. 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
containsTextureCanUseAtlas
, the engine may put the image into a texture atlas. Textures in an atlas need to rely onnormalizedTextureSubRect()
for their geometry and will not supportRepeat
. Other values fromCreateTextureOption
are ignored.When
options
containsTextureIsOpaque
, the engine will create an RGB texture which returns false forhasAlphaChannel()
. 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
containsTextureHasMipmaps
, 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 andGL_RGBA
as internal format. ReimplementQSGTexture
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 usingdeleteLater()
in the case where the texture already has affinity to the rendering thread.This function can be called from any thread.
See also
-
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 viaQQuickRenderControl
. When using aQQuickRenderControl
, theQQuickWindow
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 otherQQuickWindow
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.
See also
-
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 usingsetIncubationController()
.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
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
context –
QOpenGLContext
-
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. ThesetPersistentOpenGLContext()
andsetPersistentSceneGraph()
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.
See also
-
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.
See also
-
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 firstQQuickWindow
in the application has been constructed.See also
-
PySide2.QtQuick.QQuickWindow.
sceneGraphError
(error, message)¶ - Parameters
error –
SceneGraphError
message – unicode
-
PySide2.QtQuick.QQuickWindow.
sceneGraphInitialized
()¶
-
PySide2.QtQuick.QQuickWindow.
sceneGraphInvalidated
()¶
-
PySide2.QtQuick.QQuickWindow.
scheduleRenderJob
(job, schedule)¶ - Parameters
job –
QRunnable
schedule –
RenderStage
Schedules
job
to run when the rendering of this window reaches the givenstage
.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 theQQuickWindow
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
isNoStage
,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 aNoStage
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, callupdate()
;
-
PySide2.QtQuick.QQuickWindow.
sendEvent
(arg__1, arg__2)¶ - Parameters
arg__1 –
QQuickItem
arg__2 –
QEvent
- Return type
bool
Propagates an event
e
to aQQuickItem
item
on the window.Use
sendEvent()
directly instead.The return value is currently not used.
-
PySide2.QtQuick.QQuickWindow.
setClearBeforeRendering
(enabled)¶ - Parameters
enabled –
bool
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.
See also
-
static
PySide2.QtQuick.QQuickWindow.
setDefaultAlphaBuffer
(useAlpha)¶ - Parameters
useAlpha –
bool
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.See also
-
PySide2.QtQuick.QQuickWindow.
setPersistentOpenGLContext
(persistent)¶ - Parameters
persistent –
bool
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 theopenglContext()
when the OpenGL context is about to be released. ThesceneGraphInitialized()
signal is emitted when a new OpenGL context is created for this window. Make aDirectConnection
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.
See also
isPersistentOpenGLContext()
setPersistentSceneGraph()
aboutToBeDestroyed()
sceneGraphInitialized()
-
PySide2.QtQuick.QQuickWindow.
setPersistentSceneGraph
(persistent)¶ - Parameters
persistent –
bool
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. ThesceneGraphInitialized()
signal is emitted when a new scene graph is recreated for this window. Make aDirectConnection
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
fboId –
uint
size –
QSize
This is an overloaded function.
Sets the render target for this window to be an FBO with
fboId
andsize
.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
fbo –
QOpenGLFramebufferObject
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
-
static
PySide2.QtQuick.QQuickWindow.
setSceneGraphBackend
(backend)¶ - Parameters
backend – unicode
-
static
PySide2.QtQuick.QQuickWindow.
setTextRenderType
(renderType)¶ - Parameters
renderType –
TextRenderType
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
-
static
PySide2.QtQuick.QQuickWindow.
textRenderType
()¶ - Return type
Returns the render type of text-like elements in Qt Quick. The default is
QtTextRendering
.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.