QQuickCanvas ClassThe QQuickCanvas class provides the canvas for displaying a graphical QML scene More... #include <QQuickCanvas> Inherits: QWindow. Inherited by: QQuickView. This class was introduced in QtQuick 2.0. Public Types
PropertiesPublic Functions
Reimplemented Public Functions
Public Slots
Signals
Protected Functions
Reimplemented Protected Functions
Additional Inherited Members
Detailed DescriptionThe QQuickCanvas class provides the canvas for displaying a graphical QML scene QQuickCanvas provides the graphical scene management needed to interact with and display a scene of QQuickItems. A QQuickCanvas always has a single invisible root item. To add items to this canvas, 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. Scene Graph and RenderingThe QQuickCanvas uses a scene graph on top of OpenGL to render. 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. The rendering of each frame is broken down into the following steps, in the given order:
All of the above happen on the rendering thread, when applicable. While the scene graph is being rendered on the rendering thread, the GUI will process animations for the next frame. This means that as long as users are not using scene graph API directly, the added complexity of a rendering thread can be completely ignored. When a QQuickCanvas is programatically hidden with hide() or setVisible(false), it will stop rendering and its scene graph and OpenGL context might be released. The sceneGraphInvalidated() signal will be emitted when this happens. Warning: It is crucial that OpenGL 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 ManagementQML will typically try to cache images, scene graph nodes, etc 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 clean up of certain resources. Calling releaseResources() may result in the entire scene graph and its OpenGL context being deleted. The sceneGraphInvalidated() signal will be emitted when this happens. Member Type Documentation
flags QQuickCanvas::CreateTextureOptions |
Constant | Value | Description |
---|---|---|
QQuickCanvas::TextureHasAlphaChannel | 0x0001 | The texture has an alpha channel and should be drawn using blending. |
QQuickCanvas::TextureHasMipmaps | 0x0002 | The texture has mipmaps and can be drawn with mipmapping enabled. |
QQuickCanvas::TextureOwnsGLTexture | 0x0004 | The texture object owns the texture id and will delete the GL texture when the texture object is deleted. |
The CreateTextureOptions type is a typedef for QFlags<CreateTextureOption>. It stores an OR combination of CreateTextureOption values.
Access functions:
QColor | clearColor() const |
void | setClearColor(const QColor & color) |
Notifier signal:
void | clearColorChanged(const QColor &) |
Returns the item which currently has active focus.
This signal is emitted after the scene has completed rendering, before swapbuffers is called.
This signal can be used to paint using raw GL on top of QML content, or to do screen scraping of the current frame buffer.
The GL context used for rendering the scene graph will be bound at this point.
Warning: Since this signal is emitted from the scene graph rendering thread, the receiver should be on the scene graph thread or the connection should be Qt::DirectConnection.
Warning: Make very sure that a signal handler for afterRendering() 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.
This signal is emitted before the scene starts rendering.
Combined with the modes for clearing the background, this option can be used to paint using raw GL under QML content.
The GL context used for rendering the scene graph will be bound at this point.
Warning: Since this signal is emitted from the scene graph rendering thread, the receiver should be on the scene graph thread or the connection should be Qt::DirectConnection.
Warning: Make very sure that a signal handler for beforeRendering 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.
Returns weither clearing of the color buffer is done before rendering or not.
See also setClearBeforeRendering().
Creates a new QSGTexture object from an existing GL texture id.
The caller of the function is responsible for deleting the returned texture.
Use options to customize the texture attributes.
Warning: This function will return 0 if the scenegraph has not yet been initialized.
See also sceneGraphInitialized().
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. The actual GL texture will be deleted when the texture object is deleted.
Warning: This function will return 0 if the scene graph has not yet been initialized.
This function can be called both from the GUI thread and the rendering thread.
See also sceneGraphInitialized().
Reimplemented from QObject::event().
Reimplemented from QWindow::exposeEvent().
Reimplemented from QWindow::focusInEvent().
Reimplemented from QWindow::focusOutEvent().
Grabs the contents of the framebuffer and returns it as an image.
This function might not work if the view is not visible.
Warning: Calling this function will cause performance problems.
Warning: This function can only be called from the GUI thread.
Reimplemented from QWindow::hideEvent().
Returns an incubation controller that splices incubation between frames for this canvas. QQuickView automatically installs this controller for you, otherwise you will need to install it yourself using QQmlEngine::setIncubationController
The controller is owned by the canvas and will be destroyed when the canvas is deleted.
Returns whether the OpenGL context can be released as a part of a call to releaseResources().
Returns whether the scene graph nodes and resources can be released as a part of a call to releaseResources().
Reimplemented from QWindow::keyPressEvent().
Reimplemented from QWindow::keyReleaseEvent().
Reimplemented from QWindow::mouseDoubleClickEvent().
Returns the item which currently has the mouse grab.
Reimplemented from QWindow::mouseMoveEvent().
Reimplemented from QWindow::mousePressEvent().
Reimplemented from QWindow::mouseReleaseEvent().
Returns the opengl context used for rendering.
If the scene graph is not ready, this function will return 0.
See also sceneGraphInitialized() and sceneGraphInvalidated().
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.
See also sceneGraphInvalidated(), setPersistentOpenGLContext(), setPersistentSceneGraph(), and ..
Returns the render target for this canvas.
The default is to render to the surface of the canvas, in which case the render target is 0.
See also setRenderTarget().
Returns the FBO id of the render target when set; otherwise returns 0.
Returns the size of the currently set render target; otherwise returns an enpty size.
Reimplemented from QWindow::resizeEvent().
Returns the invisible root item of the scene.
A QQuickCanvas always has a single invisible root item. To add items to this canvas, reparent the items to the root item or to an existing item in the scene.
Propagates an event to a QQuickItem on the canvas
Sets weither the scene graph rendering of QML should clear the color buffer before it starts rendering to enbled.
By disabling clearing of the color buffer, it is possible to do GL painting under the scene graph.
The color buffer is cleared by default.
See also clearBeforeRendering() and beforeRendering().
Controls whether the OpenGL context can be released as a part of a call to releaseResources().
The OpenGL context might still be released when the user makes an explicit call to hide().
See also isPersistentOpenGLContext() and setPersistentSceneGraph().
Controls whether the scene graph nodes and resources can be released as a part of a call to releaseResources().
The scene graph nodes and resources might still be released when the user makes an explicit call to hide().
See also isPersistentSceneGraph() and setPersistentOpenGLContext().
Sets the render target for this canvas to be fbo.
The specified fbo must be created in the context of the canvas or one that shares with it.
Warning: This function can only be called from the thread doing the rendering.
See also renderTarget().
This is an overloaded function.
Reimplemented from QWindow::showEvent().
Schedules the canvas to render another frame.
Calling QQuickCanvas::update() differs from QQuickItem::update() in that it always triggers a repaint, regardless of changes in the underlying scene graph or not.
Reimplemented from QWindow::wheelEvent().