In questa pagina

Qt 3D: Esempio semplice in QML

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

Screenshot che mostra come viene renderizzato un oggetto 3D

"Simple" illustra come visualizzare una scena in Qt 3D.

Esecuzione dell'esempio

È possibile eseguire l'esempio da:

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

Le 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:

Progetto di esempio su 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.