Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QQuickCanvas Class

The 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

enum CreateTextureOption { TextureHasAlphaChannel, TextureHasMipmaps, TextureOwnsGLTexture }
flags CreateTextureOptions
enum SurfaceClass { Window }
enum SurfaceType { RasterSurface, OpenGLSurface }

Properties

  • color : QColor
  • data : const QQmlListProperty<QObject>
  • 10 properties inherited from QWindow
  • 1 property inherited from QObject

Public Functions

QQuickCanvas(QWindow * parent = 0)
virtual ~QQuickCanvas()
virtual ~QSurface()
QQuickItem * activeFocusItem() const
bool clearBeforeRendering() const
QColor clearColor() const
QSGTexture * createTextureFromId(uint id, const QSize & size, CreateTextureOptions options = CreateTextureOption( 0 )) const
QSGTexture * createTextureFromImage(const QImage & image) const
virtual QSurfaceFormat format() const = 0
QImage grabFrameBuffer()
QQmlIncubationController * incubationController() const
bool isPersistentOpenGLContext() const
bool isPersistentSceneGraph() const
QQuickItem * mouseGrabberItem() const
QOpenGLContext * openglContext() const
QOpenGLFramebufferObject * renderTarget() const
uint renderTargetId() const
QSize renderTargetSize() const
QQuickItem * rootItem() const
bool sendEvent(QQuickItem * item, QEvent * e)
void setClearBeforeRendering(bool enabled)
void setClearColor(const QColor & color)
void setPersistentOpenGLContext(bool persistent)
void setPersistentSceneGraph(bool persistent)
void setRenderTarget(QOpenGLFramebufferObject * fbo)
void setRenderTarget(uint fboId, const QSize & size)
virtual QSize size() const = 0
SurfaceClass surfaceClass() const
virtual QPlatformSurface * surfaceHandle() const = 0
virtual SurfaceType surfaceType() const = 0

Reimplemented Public Functions

virtual QAccessibleInterface * accessibleRoot() const
virtual QObject * focusObject() const
  • 69 public functions inherited from QWindow
  • 31 public functions inherited from QObject

Public Slots

void releaseResources()
void update()
  • 15 public slots inherited from QWindow
  • 1 public slot inherited from QObject

Signals

void afterRendering()
void beforeRendering()
void clearColorChanged(const QColor &)
void frameSwapped()
void sceneGraphInitialized()
void sceneGraphInvalidated()

Protected Functions

QQuickCanvas(QQuickCanvasPrivate & dd, QWindow * parent = 0)
QSurface(SurfaceClass type)

Reimplemented Protected Functions

virtual bool event(QEvent * e)
virtual void exposeEvent(QExposeEvent *)
virtual void focusInEvent(QFocusEvent *)
virtual void focusOutEvent(QFocusEvent *)
virtual void hideEvent(QHideEvent *)
virtual void keyPressEvent(QKeyEvent * e)
virtual void keyReleaseEvent(QKeyEvent * e)
virtual void mouseDoubleClickEvent(QMouseEvent * event)
virtual void mouseMoveEvent(QMouseEvent * event)
virtual void mousePressEvent(QMouseEvent * event)
virtual void mouseReleaseEvent(QMouseEvent * event)
virtual void resizeEvent(QResizeEvent *)
virtual void showEvent(QShowEvent *)
virtual void wheelEvent(QWheelEvent * event)
  • 17 protected functions inherited from QWindow
  • 9 protected functions inherited from QObject

Additional Inherited Members

  • 11 static public members inherited from QObject

Detailed Description

The 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 Rendering

The 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:

  • Synchronzation of the QML state into the scene graph. This is done by calling the QQuickItem::updatePaintNode() function on all items that have changed since the previous frame. When a dedicated rendering thread is used, the GUI thread is blocked during this synchroniation. This is the only time the QML items and the nodes in the scene graph interact.
  • The canvas to be rendered is made current using QOpenGLContext::makeCurrent().
  • The QQuickCanvas::beforeRendering() signal is emitted. Applications can make direct connections (Qt::DirectConnection) to this signal to use custom OpenGL calls which will then stack visually beneath the QML scene.
  • Items that have specified QSGNode::UsesPreprocess, will have their QSGNode::preprocess() function invoked.
  • The QQuickCanvas is cleared according to what is specified using QQuickCanvas::setClearBeforeRenderig() and QQuickCanvas::setClearColor().
  • The scene graph is rendered.
  • The QQuickCanvas::afterRendering() signal is emitted. Applications can make direct connections (Qt::DirectConnection) to this signal to use custom OpenGL calls which will then stack visually over the QML scene.
  • The rendered frame is swapped and QQuickCanvas::frameSwapped() is emitted.

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 Management

QML 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

enum QQuickCanvas::CreateTextureOption
flags QQuickCanvas::CreateTextureOptions

The CreateTextureOption enums are used to customize a texture is wrapped.

ConstantValueDescription
QQuickCanvas::TextureHasAlphaChannel0x0001The texture has an alpha channel and should be drawn using blending.
QQuickCanvas::TextureHasMipmaps0x0002The texture has mipmaps and can be drawn with mipmapping enabled.
QQuickCanvas::TextureOwnsGLTexture0x0004The 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.

Property Documentation

color : QColor

Access functions:

QColor clearColor() const
void setClearColor(const QColor & color)

Notifier signal:

void clearColorChanged(const QColor &)

data : const QQmlListProperty<QObject>

Member Function Documentation

QQuickCanvas::QQuickCanvas(QWindow * parent = 0)

QQuickCanvas::QQuickCanvas(QQuickCanvasPrivate & dd, QWindow * parent = 0) [protected]

QQuickCanvas::~QQuickCanvas() [virtual]

QAccessibleInterface * QQuickCanvas::accessibleRoot() const [virtual]

QQuickItem * QQuickCanvas::activeFocusItem() const

Returns the item which currently has active focus.

void QQuickCanvas::afterRendering() [signal]

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.

void QQuickCanvas::beforeRendering() [signal]

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.

bool QQuickCanvas::clearBeforeRendering() const

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

See also setClearBeforeRendering().

QSGTexture * QQuickCanvas::createTextureFromId(uint id, const QSize & size, CreateTextureOptions options = CreateTextureOption( 0 )) const

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

QSGTexture * QQuickCanvas::createTextureFromImage(const QImage & image) const

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

bool QQuickCanvas::event(QEvent * e) [virtual protected]

Reimplemented from QObject::event().

void QQuickCanvas::exposeEvent(QExposeEvent *) [virtual protected]

Reimplemented from QWindow::exposeEvent().

void QQuickCanvas::focusInEvent(QFocusEvent *) [virtual protected]

Reimplemented from QWindow::focusInEvent().

QObject * QQuickCanvas::focusObject() const [virtual]

void QQuickCanvas::focusOutEvent(QFocusEvent *) [virtual protected]

Reimplemented from QWindow::focusOutEvent().

void QQuickCanvas::frameSwapped() [signal]

QImage QQuickCanvas::grabFrameBuffer()

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.

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

Reimplemented from QWindow::hideEvent().

QQmlIncubationController * QQuickCanvas::incubationController() const

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.

bool QQuickCanvas::isPersistentOpenGLContext() const

Returns whether the OpenGL context can be released as a part of a call to releaseResources().

bool QQuickCanvas::isPersistentSceneGraph() const

Returns whether the scene graph nodes and resources can be released as a part of a call to releaseResources().

void QQuickCanvas::keyPressEvent(QKeyEvent * e) [virtual protected]

Reimplemented from QWindow::keyPressEvent().

void QQuickCanvas::keyReleaseEvent(QKeyEvent * e) [virtual protected]

Reimplemented from QWindow::keyReleaseEvent().

void QQuickCanvas::mouseDoubleClickEvent(QMouseEvent * event) [virtual protected]

Reimplemented from QWindow::mouseDoubleClickEvent().

QQuickItem * QQuickCanvas::mouseGrabberItem() const

Returns the item which currently has the mouse grab.

void QQuickCanvas::mouseMoveEvent(QMouseEvent * event) [virtual protected]

Reimplemented from QWindow::mouseMoveEvent().

void QQuickCanvas::mousePressEvent(QMouseEvent * event) [virtual protected]

Reimplemented from QWindow::mousePressEvent().

void QQuickCanvas::mouseReleaseEvent(QMouseEvent * event) [virtual protected]

Reimplemented from QWindow::mouseReleaseEvent().

QOpenGLContext * QQuickCanvas::openglContext() const

Returns the opengl context used for rendering.

If the scene graph is not ready, this function will return 0.

See also sceneGraphInitialized() and sceneGraphInvalidated().

void QQuickCanvas::releaseResources() [slot]

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

QOpenGLFramebufferObject * QQuickCanvas::renderTarget() const

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

uint QQuickCanvas::renderTargetId() const

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

QSize QQuickCanvas::renderTargetSize() const

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

void QQuickCanvas::resizeEvent(QResizeEvent *) [virtual protected]

Reimplemented from QWindow::resizeEvent().

QQuickItem * QQuickCanvas::rootItem() const

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.

void QQuickCanvas::sceneGraphInitialized() [signal]

void QQuickCanvas::sceneGraphInvalidated() [signal]

bool QQuickCanvas::sendEvent(QQuickItem * item, QEvent * e)

Propagates an event to a QQuickItem on the canvas

void QQuickCanvas::setClearBeforeRendering(bool enabled)

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

void QQuickCanvas::setPersistentOpenGLContext(bool persistent)

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

void QQuickCanvas::setPersistentSceneGraph(bool persistent)

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

void QQuickCanvas::setRenderTarget(QOpenGLFramebufferObject * fbo)

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

void QQuickCanvas::setRenderTarget(uint fboId, const QSize & size)

This is an overloaded function.

void QQuickCanvas::showEvent(QShowEvent *) [virtual protected]

Reimplemented from QWindow::showEvent().

void QQuickCanvas::update() [slot]

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.

void QQuickCanvas::wheelEvent(QWheelEvent * event) [virtual protected]

Reimplemented from QWindow::wheelEvent().

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 5.0-snapshot
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web