Sophie

Sophie

distrib > Mageia > 6 > x86_64 > media > core-updates > by-pkgid > 19952c5e751bf7e3108c3c59625b0f35 > files > 333

qtcharts5-doc-5.9.4-1.mga6.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- examples-legend.qdoc -->
  <title>Legend Example | Qt Charts 5.9</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.9</td><td ><a href="qtcharts-index.html">Qt Charts</a></td><td ><a href="qtcharts-examples.html">Qt Charts Examples</a></td><td >Legend Example</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.9.4 Reference Documentation</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="#detaching-and-attaching-legends">Detaching and Attaching Legends</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Legend Example</h1>
<span class="subtitle"></span>
<!-- $$$legend-description -->
<div class="descr"> <a name="details"></a>
<p>By default the chart draws the legend inside the same view with the chart. In some cases the user may want to draw the legend to somewhere else. To make this possible the legend can be detached from the chart. Detaching means that the chart doesn't draw the legend or try to change its layout. Detached legend can then be drawn wherever the user wishes, for example, in a different graphics scene. The behavior of the legend can be inspected by running the legend example. In the example we use the bar series where we add or remove the bar sets. The legend reflects the changes in series. The legend can be detached or attached back to the chart and its alignment can be modified. When the legend is detached, it can be resized and positioned freely.</p>
<p class="centerAlign"><img src="images/examples_legend_detach.png" alt="" /></p><p class="centerAlign"><img src="images/examples_legend_detach2.png" alt="" /></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="detaching-and-attaching-legends"></a>
<h2 id="detaching-and-attaching-legends">Detaching and Attaching Legends</h2>
<p>Here we turn the legend visible and set its alignment to the bottom of the chart.</p>
<pre class="cpp">

      m_chart<span class="operator">-</span><span class="operator">&gt;</span>legend()<span class="operator">-</span><span class="operator">&gt;</span>setVisible(<span class="keyword">true</span>);
      m_chart<span class="operator">-</span><span class="operator">&gt;</span>legend()<span class="operator">-</span><span class="operator">&gt;</span>setAlignment(<span class="type">Qt</span><span class="operator">::</span>AlignBottom);

</pre>
<p>This snippet shows how to detach the legend from the chart. After detaching, we turn its background to visible and set a different color to it. This makes it easier to see how the items inside the legend are arranged in detached mode.</p>
<pre class="cpp">

  legend<span class="operator">-</span><span class="operator">&gt;</span>detachFromChart();
  m_chart<span class="operator">-</span><span class="operator">&gt;</span>legend()<span class="operator">-</span><span class="operator">&gt;</span>setBackgroundVisible(<span class="keyword">true</span>);
  m_chart<span class="operator">-</span><span class="operator">&gt;</span>legend()<span class="operator">-</span><span class="operator">&gt;</span>setBrush(<span class="type">QBrush</span>(<span class="type">QColor</span>(<span class="number">128</span><span class="operator">,</span> <span class="number">128</span><span class="operator">,</span> <span class="number">128</span><span class="operator">,</span> <span class="number">128</span>)));
  m_chart<span class="operator">-</span><span class="operator">&gt;</span>legend()<span class="operator">-</span><span class="operator">&gt;</span>setPen(<span class="type">QPen</span>(<span class="type">QColor</span>(<span class="number">192</span><span class="operator">,</span> <span class="number">192</span><span class="operator">,</span> <span class="number">192</span><span class="operator">,</span> <span class="number">192</span>)));

</pre>
<p>Here we attach the legend back to the chart. The background is turned invisible.</p>
<pre class="cpp">

  legend<span class="operator">-</span><span class="operator">&gt;</span>attachToChart();
  legend<span class="operator">-</span><span class="operator">&gt;</span>setBackgroundVisible(<span class="keyword">false</span>);

</pre>
<p>This shows how we set the detached legend dimensions. After setting the new values, we call update to show changes on screen.</p>
<pre class="cpp">

      m_chart<span class="operator">-</span><span class="operator">&gt;</span>legend()<span class="operator">-</span><span class="operator">&gt;</span>setGeometry(<span class="type">QRectF</span>(m_legendPosX<span class="operator">-</span><span class="operator">&gt;</span>value()<span class="operator">,</span>
                                            m_legendPosY<span class="operator">-</span><span class="operator">&gt;</span>value()<span class="operator">,</span>
                                            m_legendWidth<span class="operator">-</span><span class="operator">&gt;</span>value()<span class="operator">,</span>
                                            m_legendHeight<span class="operator">-</span><span class="operator">&gt;</span>value()));
      m_chart<span class="operator">-</span><span class="operator">&gt;</span>legend()<span class="operator">-</span><span class="operator">&gt;</span>update();

</pre>
<p>Files:</p>
<ul>
<li><a href="qtcharts-legend-mainwidget-cpp.html">legend/mainwidget.cpp</a></li>
<li><a href="qtcharts-legend-mainwidget-h.html">legend/mainwidget.h</a></li>
<li><a href="qtcharts-legend-main-cpp.html">legend/main.cpp</a></li>
<li><a href="qtcharts-legend-legend-pro.html">legend/legend.pro</a></li>
</ul>
</div>
<!-- @@@legend -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2017 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>