Qt Quick 3D - Esempio HelloCube
Mostra come visualizzare insieme oggetti 2D e 3D in Qt Quick 3D.

HelloCube mostra come visualizzare un cubo 3D insieme a elementi 2D in Qt Quick 3D.
Disegnare elementi 2D
Configuriamo l’intera scena nel file main.qml.
Per poter utilizzare i tipi presenti nel modulo ` QtQuick3D `, è necessario importarlo:
import QtQuick3DDefiniamo semplici elementi " QtQuick " con un'immagine e un testo su un rettangolo.
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")
}Questo semplice rettangolo presenta due animazioni per il ribaltamento verticale.
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
}Disegnare un cubo 3D
Disegnare un cubo è molto semplice. Dopo aver definito un ` Camera` e un ` Light`, creiamo un cubo utilizzando l’` Model` integrato. In questo esempio, rendiamo il precedente rettangolo 2D sulla superficie di questo cubo come una ` Texture` diffusa. Nel nostro rettangolo, impostiamo ` layer.enabled ` su ` true`.
layer.enabled: trueQuando è abilitata, questa proprietà fa sì che l’elemento 2D venga renderizzato su una superficie fuori schermo, che utilizzeremo poi come texture per il nostro cubo.
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.