Qt 3D: Esempio semplice in QML
Un'applicazione QML che mostra come visualizzare una scena in Qt 3D.

"Simple" illustra come visualizzare una scena in Qt 3D.
Esecuzione dell'esempio
È possibile eseguire l'esempio da:
- Qt Creator
Aprire la modalità " Welcome " e selezionare l'esempio da Examples. Per ulteriori informazioni, consultare Qt Creator: Tutorial: Compilazione ed esecuzione.
- Qt Extension for Visual Studio Code
Eseguire il comando Qt: Open Qt examples da Command Palette e selezionare l’esempio dall’elenco. Per ulteriori informazioni, consultare Qt Extension for Visual Studio Code: Tutorial: Compilazione ed esecuzione.
Configurazione della scena
Configuriamo l’intera scena nel file main.qml.
Per poter utilizzare i tipi presenti nei moduli Q3D e Q3D Render, è necessario importare i moduli:
import Qt3D.Core 2.0
import Qt3D.Render 2.0Le prime entità che creiamo sono un ` Camera`, che rappresenta la telecamera utilizzata per il rendering finale, e un controller della telecamera, che ci permette di controllare questa telecamera utilizzando la tastiera o il mouse:
Camera {
id: camera
projectionType: CameraLens.PerspectiveProjection
fieldOfView: 45
aspectRatio: 16/9
nearPlane : 0.1
farPlane : 1000.0
position: Qt.vector3d( 0.0, 0.0, -40.0 )
upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
}Un’entità ` RenderSettings ` specifica un `ForwardRenderer` come framegraph attivo:
components: [
RenderSettings {
activeFrameGraph: ForwardRenderer {
clearColor: Qt.rgba(0, 0.5, 1, 1)
camera: camera
showDebugOverlay: true
}
},
// Event Source will be set by the Qt3DQuickWindow
InputSettings { }
]La fonte dell’evento è impostata dalla Qt3DQuickWindow:
InputSettings { }© 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.