Qt Quick 3D - HelloCube Beispiel
Zeigt, wie 2D- und 3D-Objekte zusammen in Qt Quick 3D gerendert werden können.
HelloCube demonstriert das Rendern eines 3D-Würfels mit 2D-Elementen in Qt Quick 3D.
Zeichnen von 2D-Elementen
Wir richten die gesamte Szene in der Datei main.qml ein.
Um die Typen im Modul QtQuick3D verwenden zu können, müssen wir es importieren:
import QtQuick3D
Wir definieren einfache QtQuick Items mit einem Bild und einem Text auf einem Rechteck.
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") }
Dieses einfache Rechteck hat zwei Animationen zum vertikalen Kippen.
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 }
Zeichnen eines 3D-Würfels
Das Zeichnen eines Würfels ist sehr einfach. Nachdem wir ein Camera und ein Light definiert haben, erstellen wir einen Würfel mit einem eingebauten Model. In diesem Beispiel rendern wir das vorherige 2D-Rechteck auf dieser Würfeloberfläche als diffuses Texture. In unserem Rechteck setzen wir layer.enabled
auf true
.
layer.enabled: true
Wenn diese Eigenschaft aktiviert ist, wird das 2D-Element in eine Offscreen-Oberfläche gerendert, die wir dann als Textur für unseren Würfel verwenden.
id: cube source: "#Cube" materials: DefaultMaterial { diffuseMap: Texture { sourceItem: qt_logo } } eulerRotation.y: 90
© 2025 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.