Qt Quick 3D - Exemple HelloCube
Démontre comment rendre des objets 2D et 3D ensemble dans Qt Quick 3D.

HelloCube montre comment rendre un cube 3D avec des objets 2D dans Qt Quick 3D.
Dessiner des objets 2D
Nous avons configuré l'ensemble de la scène dans le fichier main.qml.
Pour pouvoir utiliser les types du module QtQuick3D, nous devons l'importer :
import QtQuick3D
Nous définissons des éléments simples QtQuick avec une image et un texte sur un rectangle.
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") }
Ce simple rectangle a deux animations pour se retourner verticalement.
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 }
Dessiner un cube 3D
Dessiner un cube est très simple. Après avoir défini un Camera, et un Light, nous créons un cube avec un Model intégré. Dans cet exemple, nous rendons le rectangle 2D précédent sur la surface du cube sous la forme d'une image diffuse Texture. Dans notre rectangle, nous définissons layer.enabled sur true.
layer.enabled: true
Lorsqu'elle est activée, cette propriété rend l'élément 2D dans une surface hors écran, que nous utilisons ensuite comme texture pour notre cube.
id: cube source: "#Cube" materials: PrincipledMaterial { baseColorMap: Texture { sourceItem: qt_logo } } eulerRotation.y: 90
© 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.