En esta página

Qt Quick 3D - Ejemplo de HelloCube

Muestra cómo renderizar objetos 2D y 3D juntos en un entorno 3D de Qt Quick.

Cubo con el logotipo de Qt y texto en cada cara que muestra elementos 2D representados en un objeto 3D

HelloCube muestra cómo renderizar un cubo 3D junto con elementos 2D en Qt Quick 3D.

Dibujar elementos 2D

Configuramos toda la escena en el archivo main.qml.

Para poder utilizar los tipos del módulo « QtQuick3D », debemos importarlo:

import QtQuick3D

Definimos elementos sencillos de « QtQuick » con una imagen y un texto sobre un rectángulo.

Image {
    anchors.fill: parent
    source: "qt_logo.png"
}
Text {
    anchors.bottom: parent.bottom
    anchors.left: parent.left
    color: "white"
    font.pixelSize: 17
    text: qsTr("The Future is Written with Qt")
}

Este sencillo rectángulo tiene dos animaciones para girar verticalmente.

transform: Rotation {
    id: rotation
    origin.x: qt_logo.width / 2
    origin.y: qt_logo.height / 2
    axis { x: 1; y: 0; z: 0 }
}

PropertyAnimation {
    id: flip1
    target: rotation
    property: "angle"
    duration: 600
    to: 180
    from: 0
}
PropertyAnimation {
    id: flip2
    target: rotation
    property: "angle"
    duration: 600
    to: 360
    from: 180
}

Dibujar un cubo en 3D

Dibujar un cubo es muy sencillo. Tras definir un ` Camera` y un ` Light`, creamos un cubo con un ` Model` integrado. En este ejemplo, renderizamos el rectángulo 2D anterior sobre la superficie de este cubo como una textura difusa ` Texture`. En nuestro rectángulo, establecemos ` layer.enabled ` en ` true`.

layer.enabled: true

Cuando está activada, esta propiedad hace que el elemento 2D se represente en una superficie fuera de pantalla, que luego utilizamos como textura para nuestro cubo.

id: cube
source: "#Cube"
materials: PrincipledMaterial {
    baseColorMap: Texture {
        sourceItem: qt_logo
    }
}
eulerRotation.y: 90

Proyecto de ejemplo en @code.qt.io

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