Qt3DRender::Quick::QScene2D Class | Qt 3D | Qt 6.12.0
Description: This class enables rendering qml into a texture, which then can be used as a part of 3D scene.
Keywords: class

- Qt 6.12
- Qt 3D
- C++ Classes
- Qt3DScene2D (Deprecated)
- QScene2D
- Qt 6.12.0 Reference Documentation

# Qt3DRender::Quick::QScene2D Class

class Qt3DRender::Quick::QScene2D

This class enables rendering qml into a texture, which then can be used as a part of 3D scene. More...

Header: | `#include <Qt3DQuickScene2D/QScene2D>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS 3dquickscene2d)` `target_link_libraries(mytarget PRIVATE Qt6::3dquickscene2d)`
qmake: | `QT += 3dquickscene2d`
In QML: | Scene2D
Inherits: | Qt3DCore::QNode
Status: | Deprecated

This class is deprecated. We strongly advise against using it in new code.

- List of all members, including inherited members

## Public Types

enum | RenderPolicy { Continuous, SingleShot }

## Properties

- item : QQuickItem*
- mouseEnabled : bool
- output : Qt3DRender::QRenderTargetOutput*
- renderPolicy : RenderPolicy

## Public Functions

| QScene2D(Qt3DCore::QNode *parent = nullptr)
void | addEntity(Qt3DCore::QEntity *entity)
QList<Qt3DCore::QEntity *> | entities() const
bool | isMouseEnabled() const
QQuickItem * | item() const
Qt3DRender::QRenderTargetOutput * | output() const
void | removeEntity(Qt3DCore::QEntity *entity)
Qt3DRender::Quick::QScene2D::RenderPolicy | renderPolicy() const

## Public Slots

void | setItem(QQuickItem *item)
void | setMouseEnabled(bool enabled)
void | setOutput(Qt3DRender::QRenderTargetOutput *output)
void | setRenderPolicy(Qt3DRender::Quick::QScene2D::RenderPolicy policy)

## Signals

void | itemChanged(QQuickItem *item)
void | mouseEnabledChanged(bool enabled)
void | outputChanged(Qt3DRender::QRenderTargetOutput *output)
void | renderPolicyChanged(Qt3DRender::Quick::QScene2D::RenderPolicy policy)

## Detailed Description

This class uses QQuickRenderControl to render the given QQuickItem into an offscreen surface, which is attached to a texture provided by the user. This allows the component to directly render into the texture without intermediate copy and the user to freely specify how the texture is used in the 3D scene.

The entities using the QScene2D can be associated with the class to enable interaction with the item; if an entity has a QObjectPicker component, the pick events from that picker are sent to the QScene2D and converted to mouse events and finally sent to the item.

Note: Only mouse events are supported. The item does not support keyboard input.

## Member Type Documentation

### enum QScene2D::RenderPolicy

This enum type describes types of render policies available.

Constant | Value | Description
--- | --- | ---
`Qt3DRender::Quick::QScene2D::Continuous` | `0` | The Scene2D is rendering continuously. This is the default render policy.
`Qt3DRender::Quick::QScene2D::SingleShot` | `1` | The Scene2D renders to the texture only once after which the resources allocated for rendering are released.

## Property Documentation

### item : QQuickItem*

Holds the QQuickItem, which is rendered by QScene2D to the texture.

Access functions:

QQuickItem * | item() const
void | setItem(QQuickItem *item)

Notifier signal:

void | itemChanged(QQuickItem *item)

### mouseEnabled : bool

Holds whether mouse events are enabled for the rendered item. The mouse events are generated from object picking events of the entities added to the QScene2D. Mouse is enabled by default.

Note: Events are delayed by one frame due to object picking happening in the backend.

Access functions:

bool | isMouseEnabled() const
void | setMouseEnabled(bool enabled)

Notifier signal:

void | mouseEnabledChanged(bool enabled)

### output : Qt3DRender::QRenderTargetOutput*

Holds the QRenderTargetOutput, which specifies where the QScene2D is rendering to.

Access functions:

Qt3DRender::QRenderTargetOutput * | output() const
void | setOutput(Qt3DRender::QRenderTargetOutput *output)

Notifier signal:

void | outputChanged(Qt3DRender::QRenderTargetOutput *output)

### renderPolicy : RenderPolicy

Holds the render policy of this Scene2D.

Access functions:

Qt3DRender::Quick::QScene2D::RenderPolicy | renderPolicy() const
void | setRenderPolicy(Qt3DRender::Quick::QScene2D::RenderPolicy policy)

Notifier signal:

void | renderPolicyChanged(Qt3DRender::Quick::QScene2D::RenderPolicy policy)

## Member Function Documentation

### `[explicit]` QScene2D::QScene2D(Qt3DCore::QNode *parent = nullptr)

The constructor creates a new QScene2D instance with the specified parent.

### void QScene2D::addEntity(Qt3DCore::QEntity *entity)

Adds an entity to the the QScene2D object. If the entities have QObjectPicker, the pick events from that entity are sent to QScene2D and converted to mouse events.

### QList<Qt3DCore::QEntity *> QScene2D::entities() const

Retrieve entities associated with the QScene2D.

### void QScene2D::removeEntity(Qt3DCore::QEntity *entity)

Removes an entity from the the QScene2D object.