<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- simple-qml.qdoc --> <title>Qt 3D: Simple QML Example | Qt 3D 5.12.6</title> <link rel="stylesheet" type="text/css" href="style/offline-simple.css" /> <script type="text/javascript"> document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css"); // loading style sheet breaks anchors that were jumped to before // so force jumping to anchor again setTimeout(function() { var anchor = location.hash; // need to jump to different anchor first (e.g. none) location.hash = "#"; setTimeout(function() { location.hash = anchor; }, 0); }, 0); </script> </head> <body> <div class="header" id="qtdocheader"> <div class="main"> <div class="main-rounded"> <div class="navigationbar"> <table><tr> <td >Qt 5.12</td><td ><a href="qt3d-index.html">Qt 3D</a></td><td >Qt 3D: Simple QML Example</td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right"><a href="qt3d-index.html">Qt 5.12.6 Reference Documentation</a></td> </tr></table> </div> </div> <div class="content"> <div class="line"> <div class="content mainContent"> <div class="sidebar"> <div class="toc"> <h3><a name="toc">Contents</a></h3> <ul> <li class="level1"><a href="#running-the-example">Running the Example</a></li> <li class="level1"><a href="#setting-up-the-scene">Setting Up the Scene</a></li> </ul> </div> <div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">Qt 3D: Simple QML Example</h1> <span class="subtitle"></span> <!-- $$$simple-qml-brief --> <p>A QML application that demonstrates how to render a scene in Qt 3D.</p> <!-- @@@simple-qml --> <!-- $$$simple-qml-description --> <div class="descr"> <a name="details"></a> <p class="centerAlign"><img src="images/simple-qml.png" alt="" /></p><p><i>Simple</i> demonstrates how to render a scene in Qt 3D.</p> <a name="running-the-example"></a> <h2 id="running-the-example">Running the Example</h2> <p>To run the example from Qt Creator, open the <b>Welcome</b> mode and select the example from <b>Examples</b>. For more information, visit Building and Running an Example.</p> <a name="setting-up-the-scene"></a> <h2 id="setting-up-the-scene">Setting Up the Scene</h2> <p>We set up the entire scene in the <i>main.qml</i> file.</p> <p>To be able to use the types in the Q3D and Q3D Render modules, we must import the modules:</p> <pre class="cpp"> import Qt3D.Core 2.0 import Qt3D.Render 2.0 </pre> <p>The first entities we create are a <a href="qml-qt3d-render-camera.html">Camera</a>, which represents the camera used for the final rendering, and a camera controller, which allows us to control this camera using the keyboard or the mouse:</p> <pre class="cpp"> 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 ) } OrbitCameraController { camera: camera } </pre> <p>A <a href="qml-qt3d-render-rendersettings.html">RenderSettings</a> entity specifies a <a href="qml-qt3d-extras-forwardrenderer.html">ForwardRenderer</a> as the active framegraph:</p> <pre class="cpp"> components: [ RenderSettings { activeFrameGraph: ForwardRenderer { clearColor: Qt.rgba(0, 0.5, 1, 1) camera: camera } }, </pre> <p>The event source is set by the Qt3DQuickWindow:</p> <pre class="cpp"> InputSettings { } </pre> <p>Files:</p> <ul> <li><a href="qt3d-simple-qml-main-cpp.html">simple-qml/main.cpp</a></li> <li><a href="qt3d-simple-qml-main-qml.html">simple-qml/main.qml</a></li> <li><a href="qt3d-simple-qml-simple-qml-pro.html">simple-qml/simple-qml.pro</a></li> <li><a href="qt3d-simple-qml-simple-qml-qrc.html">simple-qml/simple-qml.qrc</a></li> </ul> </div> <!-- @@@simple-qml --> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2019 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.<br/> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br/> 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. </p> </div> </body> </html>