<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- qmlspectrogram.qdoc --> <title>Qt Quick 2 Spectrogram Example | Qt Data Visualization 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="qtdatavisualization-index.html">Qt Data Visualization</a></td><td >Qt Quick 2 Spectrogram Example</td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right"><a href="qtdatavisualization-index.html">Qt Data Visualization | Commercial or GPLv3</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="#creating-a-spectrogram">Creating a Spectrogram</a></li> <li class="level1"><a href="#polar-spectrogram">Polar Spectrogram</a></li> <li class="level1"><a href="#example-contents">Example Contents</a></li> </ul> </div> <div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">Qt Quick 2 Spectrogram Example</h1> <span class="subtitle"></span> <!-- $$$qmlspectrogram-brief --> <p>Showing spectrogram graph in a QML application.</p> <!-- @@@qmlspectrogram --> <!-- $$$qmlspectrogram-description --> <div class="descr"> <a name="details"></a> <p>The Qt Quick 2 Spectrogram example demonstrates how to show a polar and cartesian spectrograms and how to utilize orthographic projection to show them in 2D.</p> <p class="centerAlign"><img src="images/qmlspectrogram-example.png" alt="" /></p><p>Spectrogram is simply a surface graph with a range gradient used to emphasize the different values. Typically spectrograms are shown with two dimensional surfaces, which we simulate with a top down orthographic view of the graph. To enforce the 2D effect, we disable the graph rotation via mouse or touch when in the orthographic mode.</p> <p>The focus in this example is on showing how to display spectrograms, so the basic functionality is not explained. For more detailed QML example documentation, see <a href="qtdatavisualization-qmlscatter-example.html">Qt Quick 2 Scatter Example</a>.</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="creating-a-spectrogram"></a> <h2 id="creating-a-spectrogram">Creating a Spectrogram</h2> <p>To create a 2D spectrogram, we define a <a href="qml-qtdatavisualization-surface3d.html">Surface3D</a> item:</p> <pre class="qml"> Surface3D { id: surfaceGraph width: surfaceView.width height: surfaceView.height shadowQuality: AbstractGraph3D.ShadowQualityNone selectionMode: AbstractGraph3D.SelectionSlice | AbstractGraph3D.SelectionItemAndColumn axisX: xAxis axisY: yAxis axisZ: zAxis theme: customTheme inputHandler: customInputHandler // Remove the perspective and view the graph from top down to achieve 2D effect orthoProjection: true scene.activeCamera.cameraPreset: Camera3D.CameraPresetDirectlyAbove flipHorizontalGrid: true radialLabelOffset: 0.01 horizontalAspectRatio: 1 scene.activeCamera.zoomLevel: 85 Surface3DSeries { id: surfaceSeries flatShadingEnabled: false drawMode: Surface3DSeries.DrawSurface baseGradient: surfaceGradient colorStyle: Theme3D.ColorStyleRangeGradient itemLabelFormat: "(@xLabel, @zLabel): @yLabel" ItemModelSurfaceDataProxy { itemModel: surfaceData.model rowRole: "radius" columnRole: "angle" yPosRole: "value" } } } </pre> <p>The key properties for enabling the 2D effect are <a href="qml-qtdatavisualization-abstractgraph3d.html#orthoProjection-prop">orthoProjection</a> and <a href="qml-qtdatavisualization-camera3d.html#cameraPreset-prop">scene.activeCamera.cameraPreset</a>. We remove the perspective by enabling orthographic projection for the graph, and then we eliminate the Y-dimension by viewing the graph directly from above:</p> <pre class="qml"> orthoProjection: true scene.activeCamera.cameraPreset: Camera3D.CameraPresetDirectlyAbove </pre> <p>Since this viewpoint causes the horizontal axis grid to be mostly obscured by the surface, we also specify that the horizontal grid should be drawn on top of the graph:</p> <pre class="qml"> flipHorizontalGrid: true </pre> <a name="polar-spectrogram"></a> <h2 id="polar-spectrogram">Polar Spectrogram</h2> <p>Depending on the data, it is sometimes more natural to use a polar graph instead of a cartesian one. Qt Data Visualization supports this via <a href="qml-qtdatavisualization-abstractgraph3d.html#polar-prop">polar</a> property. In this example we provide a button to switch between polar and cartesian modes:</p> <pre class="qml"> NewButton { id: polarToggle Layout.fillWidth: true Layout.fillHeight: true text: "Switch to polar" onClicked: { if (surfaceGraph.polar === false) { surfaceGraph.polar = true text = "Switch to cartesian" } else { surfaceGraph.polar = false text = "Switch to polar" } } } </pre> <p>In the polar mode, the X-axis is converted into the angular polar axis, and the Z-axis is converted into the radial polar axis. The surface points are recalculated according to new axes.</p> <p>The radial axis labels are drawn outside the graph by default, but in this example we want to draw them right next to the 0 degree angular axis inside the graph, so we define only a tiny offset for them:</p> <pre class="qml"> radialLabelOffset: 0.01 </pre> <p>To enforce the 2D effect, graph rotation via user input is disabled when in orthographic mode. We do this by specifying a new input handler:</p> <pre class="qml"> TouchInputHandler3D { id: customInputHandler rotationEnabled: false } Surface3D { ... inputHandler: customInputHandler ... </pre> <p>When the projection mode changes, we adjust the value of the <a href="qml-qtdatavisualization-inputhandler3d.html#rotationEnabled-prop">rotationEnabled</a> property of the <code>customInputHandler</code> to control the rotation.</p> <a name="example-contents"></a> <h2 id="example-contents">Example Contents</h2> <p>Files:</p> <ul> <li><a href="qtdatavisualization-qmlspectrogram-main-cpp.html">qmlspectrogram/main.cpp</a></li> <li><a href="qtdatavisualization-qmlspectrogram-qml-qmlspectrogram-data-qml.html">qmlspectrogram/qml/qmlspectrogram/Data.qml</a></li> <li><a href="qtdatavisualization-qmlspectrogram-qml-qmlspectrogram-newbutton-qml.html">qmlspectrogram/qml/qmlspectrogram/NewButton.qml</a></li> <li><a href="qtdatavisualization-qmlspectrogram-qml-qmlspectrogram-main-qml.html">qmlspectrogram/qml/qmlspectrogram/main.qml</a></li> <li><a href="qtdatavisualization-qmlspectrogram-qmlspectrogram-pro.html">qmlspectrogram/qmlspectrogram.pro</a></li> <li><a href="qtdatavisualization-qmlspectrogram-qmlspectrogram-qrc.html">qmlspectrogram/qmlspectrogram.qrc</a></li> </ul> </div> <!-- @@@qmlspectrogram --> </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>