Nesta página

Qt Quick 3D - Exemplo do HelloCube

Demonstra como renderizar objetos 2D e 3D juntos em um Qt Quick e 3D.

Cubo com o logotipo do Qt e texto em cada face, exibindo elementos 2D renderizados em um objeto 3D

O HelloCube demonstra como renderizar um cubo 3D com itens 2D no Qt Quick 3D.

Desenhar itens 2D

Configuramos toda a cena no arquivo main.qml.

Para podermos usar os tipos do módulo ` QtQuick3D `, precisamos importá-lo:

import QtQuick3D

Definimos itens simples do QtQuick com uma imagem e um texto em um retâ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")
}

Esse retângulo simples possui duas animações 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
}

Desenhar um cubo 3D

Desenhar um cubo é muito simples. Depois de definir um ` Camera` e um ` Light`, criamos um cubo com um ` Model` embutido. Neste exemplo, renderizamos o retângulo 2D anterior na superfície desse cubo como uma textura difusa ` Texture`. Em nosso retângulo, definimos ` layer.enabled ` como ` true`.

layer.enabled: true

Quando ativada, essa propriedade faz com que o item 2D seja renderizado em uma superfície fora da tela, que então usamos como textura para o nosso cubo.

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

Projeto de exemplo em @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.