<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- graphicsview-flowlayout.qdoc --> <title>Graphics View Flow Layout Example | Qt Widgets 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="qtwidgets-index.html">Qt Widgets</a></td><td >Graphics View Flow Layout Example</td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right"><a href="qtwidgets-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="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">Graphics View Flow Layout Example</h1> <span class="subtitle"></span> <!-- $$$graphicsview/flowlayout-brief --> <p>Demonstrates flow layout on a graphics view scene.</p> <!-- @@@graphicsview/flowlayout --> <!-- $$$graphicsview/flowlayout-description --> <div class="descr"> <a name="details"></a> <p>The Graphics View Flow Layout example shows the use of a flow layout in a Graphics View widget.</p> <p class="centerAlign"><img src="images/graphicsflowlayout-example.png" alt="" /></p><p>This example uses a Graphics View to display the widget, which is a more customizable approach than displaying the flow layout in the application window (See <a href="qtwidgets-layouts-flowlayout-example.html">Flow Layout Example</a>).</p> <p>Graphics View Flow Layout snippet:</p> <pre class="cpp"> <span class="preprocessor">#include "window.h"</span> <span class="preprocessor">#include <QApplication></span> <span class="preprocessor">#include <QGraphicsView></span> <span class="type">int</span> main(<span class="type">int</span> argc<span class="operator">,</span> <span class="type">char</span> <span class="operator">*</span>argv<span class="operator">[</span><span class="operator">]</span>) { <span class="type"><a href="qapplication.html">QApplication</a></span> app(argc<span class="operator">,</span> argv); <span class="type"><a href="qgraphicsscene.html">QGraphicsScene</a></span> scene; <span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span> <span class="operator">*</span>view <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span>(<span class="operator">&</span>scene); Window <span class="operator">*</span>w <span class="operator">=</span> <span class="keyword">new</span> Window; scene<span class="operator">.</span>addItem(w); view<span class="operator">-</span><span class="operator">></span>resize(<span class="number">400</span><span class="operator">,</span> <span class="number">300</span>); view<span class="operator">-</span><span class="operator">></span>show(); <span class="keyword">return</span> app<span class="operator">.</span>exec(); } </pre> <p>Flow Layout Example snippet:</p> <pre class="cpp"> <span class="preprocessor">#include <QApplication></span> <span class="preprocessor">#include "window.h"</span> <span class="type">int</span> main(<span class="type">int</span> argc<span class="operator">,</span> <span class="type">char</span> <span class="operator">*</span>argv<span class="operator">[</span><span class="operator">]</span>) { <span class="type"><a href="qapplication.html">QApplication</a></span> app(argc<span class="operator">,</span> argv); Window window; window<span class="operator">.</span>show(); <span class="keyword">return</span> app<span class="operator">.</span>exec(); } </pre> <p>Files:</p> <ul> <li><a href="qtwidgets-graphicsview-flowlayout-flowlayout-cpp.html">graphicsview/flowlayout/flowlayout.cpp</a></li> <li><a href="qtwidgets-graphicsview-flowlayout-flowlayout-h.html">graphicsview/flowlayout/flowlayout.h</a></li> <li><a href="qtwidgets-graphicsview-flowlayout-flowlayout-pro.html">graphicsview/flowlayout/flowlayout.pro</a></li> <li><a href="qtwidgets-graphicsview-flowlayout-main-cpp.html">graphicsview/flowlayout/main.cpp</a></li> <li><a href="qtwidgets-graphicsview-flowlayout-window-cpp.html">graphicsview/flowlayout/window.cpp</a></li> <li><a href="qtwidgets-graphicsview-flowlayout-window-h.html">graphicsview/flowlayout/window.h</a></li> </ul> </div> <!-- @@@graphicsview/flowlayout --> </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>