本页内容

Scene2D QML Type

此类型支持将 QML 渲染为纹理,该纹理随后可作为 3D 场景的一部分使用。更多...

Import Statement: import QtQuick.Scene2D 2.12
In C++: QScene2D
Status: Deprecated

此类型已弃用。我们强烈建议不要在新代码中使用它。

属性

详细说明

该对象使用 RenderControl 将给定的 Item 渲染到一个离屏表面上,该表面附着在用户提供的纹理上。这使得该组件能够直接渲染到纹理中,无需中间复制,同时用户可以自由指定该纹理在 3D 场景中的使用方式。

使用 Scene2D 的实体可以与该类型关联,从而实现与该项的交互;如果某个实体拥有ObjectPicker 组件,则该选择器产生的选中事件会被发送至 Scene2D,转换为鼠标事件,最后发送给该项。

注意:仅 支持鼠标事件。该项不支持键盘输入。

用法:

Entity {
    id: sceneRoot

    // specify Scene2D inside the entity hierarchy
    Scene2D {
        // specify output
        output: RenderTargetOutput {
            attachmentPoint: RenderTargetOutput.Color0
            texture: Texture2D {
                id: textureId
                width: 1024
                height: 1024
                format: Texture.RGBA8_UNorm
            }
        }
        // specify entities
        entities: [entityId]

        // specify rendered content
        Rectangle {
            color: "red"
        }
    }

    Entity {
        id: entityId

        property Material material: TextureMaterial {
            texture: textureId
        }
        property ObjectPicker picker: ObjectPicker {
            hoverEnabled: true
            dragEnabled: true
        }
        ...

属性文档

entities : list<Entity>

存储与Scene2D 对象关联的实体列表。如果这些实体具有ObjectPicker,则该实体的选中事件会被发送至Scene2D ,并转换为鼠标事件。

item : Item

保存该项,该项由Scene2D 渲染到纹理上。

mouseEnabled : bool

表示渲染项是否启用了鼠标事件。鼠标事件由添加到Scene2D 中的实体的对象选择事件生成。默认情况下,鼠标功能处于启用状态。

注意: 由于对象选择操作在后端进行,发送到项的事件 会延迟一帧。

output : RenderTargetOutput

保存 RenderTargetOutput 对象,该对象指定了Scene2D 的渲染目标位置。

renderPolicy : enumeration

保存此Scene2D 的渲染策略。

  • Continuous 该Scene2D 正在持续渲染。这是默认的渲染策略。
  • 单次渲染(SingleShot):Scene2D 仅向纹理渲染一次,之后为渲染分配的资源将被释放。

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