<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html><head><title>QGraphicsLinearLayout Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm } a:link { color: #004faf; text-decoration: none } a:visited { color: #672967; text-decoration: none } td.postheader { font-family: sans-serif } tr.address { font-family: sans-serif } body { background: #ffffff; color: black; } </style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">  </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QGraphicsLinearLayout Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Graphics View. <a href="#details">More...</a></p> <p>Inherits <a href="qgraphicslayout.html">QGraphicsLayout</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qgraphicslinearlayout.html#QGraphicsLinearLayout">__init__</a></b> (<i>self</i>, QGraphicsLayoutItem <i>parent</i> = None)</li><li><div class="fn" /><b><a href="qgraphicslinearlayout.html#QGraphicsLinearLayout-2">__init__</a></b> (<i>self</i>, Qt.Orientation <i>orientation</i>, QGraphicsLayoutItem <i>parent</i> = None)</li><li><div class="fn" /><b><a href="qgraphicslinearlayout.html#addItem">addItem</a></b> (<i>self</i>, QGraphicsLayoutItem <i>item</i>)</li><li><div class="fn" /><b><a href="qgraphicslinearlayout.html#addStretch">addStretch</a></b> (<i>self</i>, int <i>stretch</i> = 1)</li><li><div class="fn" />Qt.Alignment <b><a href="qgraphicslinearlayout.html#alignment">alignment</a></b> (<i>self</i>, QGraphicsLayoutItem <i>item</i>)</li><li><div class="fn" />int <b><a href="qgraphicslinearlayout.html#count">count</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qgraphicslinearlayout.html#insertItem">insertItem</a></b> (<i>self</i>, int <i>index</i>, QGraphicsLayoutItem <i>item</i>)</li><li><div class="fn" /><b><a href="qgraphicslinearlayout.html#insertStretch">insertStretch</a></b> (<i>self</i>, int <i>index</i>, int <i>stretch</i> = 1)</li><li><div class="fn" /><b><a href="qgraphicslinearlayout.html#invalidate">invalidate</a></b> (<i>self</i>)</li><li><div class="fn" />QGraphicsLayoutItem <b><a href="qgraphicslinearlayout.html#itemAt">itemAt</a></b> (<i>self</i>, int <i>index</i>)</li><li><div class="fn" />float <b><a href="qgraphicslinearlayout.html#itemSpacing">itemSpacing</a></b> (<i>self</i>, int <i>index</i>)</li><li><div class="fn" />Qt.Orientation <b><a href="qgraphicslinearlayout.html#orientation">orientation</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qgraphicslinearlayout.html#removeAt">removeAt</a></b> (<i>self</i>, int <i>index</i>)</li><li><div class="fn" /><b><a href="qgraphicslinearlayout.html#removeItem">removeItem</a></b> (<i>self</i>, QGraphicsLayoutItem <i>item</i>)</li><li><div class="fn" /><b><a href="qgraphicslinearlayout.html#setAlignment">setAlignment</a></b> (<i>self</i>, QGraphicsLayoutItem <i>item</i>, Qt.Alignment <i>alignment</i>)</li><li><div class="fn" /><b><a href="qgraphicslinearlayout.html#setGeometry">setGeometry</a></b> (<i>self</i>, QRectF <i>rect</i>)</li><li><div class="fn" /><b><a href="qgraphicslinearlayout.html#setItemSpacing">setItemSpacing</a></b> (<i>self</i>, int <i>index</i>, float <i>spacing</i>)</li><li><div class="fn" /><b><a href="qgraphicslinearlayout.html#setOrientation">setOrientation</a></b> (<i>self</i>, Qt.Orientation <i>orientation</i>)</li><li><div class="fn" /><b><a href="qgraphicslinearlayout.html#setSpacing">setSpacing</a></b> (<i>self</i>, float <i>spacing</i>)</li><li><div class="fn" /><b><a href="qgraphicslinearlayout.html#setStretchFactor">setStretchFactor</a></b> (<i>self</i>, QGraphicsLayoutItem <i>item</i>, int <i>stretch</i>)</li><li><div class="fn" />QSizeF <b><a href="qgraphicslinearlayout.html#sizeHint">sizeHint</a></b> (<i>self</i>, Qt.SizeHint <i>which</i>, QSizeF <i>constraint</i> = QSizeF())</li><li><div class="fn" />float <b><a href="qgraphicslinearlayout.html#spacing">spacing</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qgraphicslinearlayout.html#stretchFactor">stretchFactor</a></b> (<i>self</i>, QGraphicsLayoutItem <i>item</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Graphics View.</p> <p>The default orientation for a linear layout is <a href="qt.html#Orientation-enum">Qt.Horizontal</a>. You can choose a vertical orientation either by calling <a href="qgraphicslinearlayout.html#setOrientation">setOrientation</a>(), or by passing <a href="qt.html#Orientation-enum">Qt.Vertical</a> to QGraphicsLinearLayout's constructor.</p> <p>The most common way to use QGraphicsLinearLayout is to construct an object on the heap with no parent, add widgets and layouts by calling <a href="qgraphicslinearlayout.html#addItem">addItem</a>(), and finally assign the layout to a widget by calling <a href="qgraphicswidget.html#layout-prop">QGraphicsWidget.setLayout</a>().</p> <pre class="cpp"> <span class="type"><a href="qgraphicsscene.html">QGraphicsScene</a></span> scene; <span class="type"><a href="qgraphicswidget.html">QGraphicsWidget</a></span> <span class="operator">*</span>textEdit <span class="operator">=</span> scene<span class="operator">.</span>addWidget(<span class="keyword">new</span> <span class="type"><a href="qtextedit.html">QTextEdit</a></span>); <span class="type"><a href="qgraphicswidget.html">QGraphicsWidget</a></span> <span class="operator">*</span>pushButton <span class="operator">=</span> scene<span class="operator">.</span>addWidget(<span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>); <span class="type">QGraphicsLinearLayout</span> <span class="operator">*</span>layout <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QGraphicsLinearLayout</span>; layout<span class="operator">-</span><span class="operator">></span><a href="qgraphicslinearlayout.html#addItem">addItem</a>(textEdit); layout<span class="operator">-</span><span class="operator">></span><a href="qgraphicslinearlayout.html#addItem">addItem</a>(pushButton); <span class="type"><a href="qgraphicswidget.html">QGraphicsWidget</a></span> <span class="operator">*</span>form <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgraphicswidget.html">QGraphicsWidget</a></span>; form<span class="operator">-</span><span class="operator">></span>setLayout(layout); scene<span class="operator">.</span><a href="qgraphicslinearlayout.html#addItem">addItem</a>(form); </pre> <p>You can add widgets, layouts, stretches (<a href="qgraphicslinearlayout.html#addStretch">addStretch</a>(), <a href="qgraphicslinearlayout.html#insertStretch">insertStretch</a>() or <a href="qgraphicslinearlayout.html#setStretchFactor">setStretchFactor</a>()), and spacings (<a href="qgraphicslinearlayout.html#setItemSpacing">setItemSpacing</a>()) to a linear layout. The layout takes ownership of the items. In some cases when the layout item also inherits from <a href="qgraphicsitem.html">QGraphicsItem</a> (such as <a href="qgraphicswidget.html">QGraphicsWidget</a>) there will be a ambiguity in ownership because the layout item belongs to two ownership hierarchies. See the documentation of <a href="qgraphicslayoutitem.html#setOwnedByLayout">QGraphicsLayoutItem.setOwnedByLayout</a>() how to handle this. You can access each item in the layout by calling <a href="qgraphicslinearlayout.html#count">count</a>() and <a href="qgraphicslinearlayout.html#itemAt">itemAt</a>(). Calling <a href="qgraphicslinearlayout.html#removeAt">removeAt</a>() or <a href="qgraphicslinearlayout.html#removeItem">removeItem</a>() will remove an item from the layout, without destroying it.</p> <a id="size-hints-and-size-policies-in-qgraphicslinearlayout" name="size-hints-and-size-policies-in-qgraphicslinearlayout" /> <h3>Size Hints and Size Policies in QGraphicsLinearLayout</h3> <p>QGraphicsLinearLayout respects each item's size hints and size policies, and when the layout contains more space than the items can fill, each item is arranged according to the layout's alignment for that item. You can set an alignment for each item by calling <a href="qgraphicslinearlayout.html#setAlignment">setAlignment</a>(), and check the alignment for any item by calling <a href="qgraphicslinearlayout.html#alignment">alignment</a>(). By default, items are aligned to the top left.</p> <a id="spacing-within-qgraphicslinearlayout" name="spacing-within-qgraphicslinearlayout" /> <h3>Spacing within QGraphicsLinearLayout</h3> <p>Between the items, the layout distributes some space. The actual amount of space depends on the managed widget's current style, but the common spacing is 4. You can also set your own spacing by calling <a href="qgraphicslinearlayout.html#setSpacing">setSpacing</a>(), and get the current spacing value by calling <a href="qgraphicslinearlayout.html#spacing">spacing</a>(). If you want to configure individual spacing for your items, you can call <a href="qgraphicslinearlayout.html#setItemSpacing">setItemSpacing</a>().</p> <a id="stretch-factor-in-qgraphicslinearlayout" name="stretch-factor-in-qgraphicslinearlayout" /> <h3>Stretch Factor in QGraphicsLinearLayout</h3> <p>You can assign a stretch factor to each item to control how much space it will get compared to the other items. By default, two identical widgets arranged in a linear layout will have the same size, but if the first widget has a stretch factor of 1 and the second widget has a stretch factor of 2, the first widget will get 1/3 of the available space, and the second will get 2/3.</p> <p>QGraphicsLinearLayout calculates the distribution of sizes by adding up the stretch factors of all items, and then dividing the available space accordingly. The default stretch factor is 0 for all items; a factor of 0 means the item does not have any defined stretch factor; effectively this is the same as setting the stretch factor to 1. The stretch factor only applies to the available space in the lengthwise direction of the layout (following its orientation). If you want to control both the item's horizontal and vertical stretch, you can use <a href="qgraphicsgridlayout.html">QGraphicsGridLayout</a> instead.</p> <a id="qgraphicslinearlayout-compared-to-other-layouts" name="qgraphicslinearlayout-compared-to-other-layouts" /> <h3>QGraphicsLinearLayout Compared to Other Layouts</h3> <p>QGraphicsLinearLayout is very similar to <a href="qvboxlayout.html">QVBoxLayout</a> and <a href="qhboxlayout.html">QHBoxLayout</a>, but in contrast to these classes, it is used to manage <a href="qgraphicswidget.html">QGraphicsWidget</a> and <a href="qgraphicslayout.html">QGraphicsLayout</a> instead of <a href="qwidget.html">QWidget</a> and <a href="qlayout.html">QLayout</a>.</p> <hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QGraphicsLinearLayout" />QGraphicsLinearLayout.__init__ (<i>self</i>, <a href="qgraphicslayoutitem.html">QGraphicsLayoutItem</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a <a href="qgraphicslinearlayout.html">QGraphicsLinearLayout</a> instance using <a href="qt.html#Orientation-enum">Qt.Horizontal</a> orientation. <i>parent</i> is passed to <a href="qgraphicslayout.html">QGraphicsLayout</a>'s constructor.</p> <h3 class="fn"><a name="QGraphicsLinearLayout-2" />QGraphicsLinearLayout.__init__ (<i>self</i>, <a href="qt.html#Orientation-enum">Qt.Orientation</a> <i>orientation</i>, <a href="qgraphicslayoutitem.html">QGraphicsLayoutItem</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a <a href="qgraphicslinearlayout.html">QGraphicsLinearLayout</a> instance. You can pass the <i>orientation</i> for the layout, either horizontal or vertical, and <i>parent</i> is passed to <a href="qgraphicslayout.html">QGraphicsLayout</a>'s constructor.</p> <h3 class="fn"><a name="addItem" />QGraphicsLinearLayout.addItem (<i>self</i>, <a href="qgraphicslayoutitem.html">QGraphicsLayoutItem</a> <i>item</i>)</h3><p>The <i>item</i> argument has it's ownership transferred to Qt.</p><p>This convenience function is equivalent to calling insertItem(-1, <i>item</i>).</p> <h3 class="fn"><a name="addStretch" />QGraphicsLinearLayout.addStretch (<i>self</i>, int <i>stretch</i> = 1)</h3><p>This convenience function is equivalent to calling insertStretch(-1, <i>stretch</i>).</p> <h3 class="fn"><a name="alignment" /><a href="qt-alignment.html">Qt.Alignment</a> QGraphicsLinearLayout.alignment (<i>self</i>, <a href="qgraphicslayoutitem.html">QGraphicsLayoutItem</a> <i>item</i>)</h3><p>Returns the alignment for <i>item</i>. The default alignment is <a href="qt.html#AlignmentFlag-enum">Qt.AlignTop</a> | <a href="qt.html#AlignmentFlag-enum">Qt.AlignLeft</a>.</p> <p>The alignment decides how the item is positioned within its assigned space in the case where there's more space available in the layout than the widgets can occupy.</p> <p><b>See also</b> <a href="qgraphicslinearlayout.html#setAlignment">setAlignment</a>().</p> <h3 class="fn"><a name="count" />int QGraphicsLinearLayout.count (<i>self</i>)</h3><p>Reimplemented from <a href="qgraphicslayout.html#count">QGraphicsLayout.count</a>().</p> <h3 class="fn"><a name="insertItem" />QGraphicsLinearLayout.insertItem (<i>self</i>, int <i>index</i>, <a href="qgraphicslayoutitem.html">QGraphicsLayoutItem</a> <i>item</i>)</h3><p>The <i>item</i> argument has it's ownership transferred to Qt.</p><p>Inserts <i>item</i> into the layout at <i>index</i>, or before any item that is currently at <i>index</i>.</p> <p><b>See also</b> <a href="qgraphicslinearlayout.html#addItem">addItem</a>(), <a href="qgraphicslinearlayout.html#itemAt">itemAt</a>(), <a href="qgraphicslinearlayout.html#insertStretch">insertStretch</a>(), and <a href="qgraphicslinearlayout.html#setItemSpacing">setItemSpacing</a>().</p> <h3 class="fn"><a name="insertStretch" />QGraphicsLinearLayout.insertStretch (<i>self</i>, int <i>index</i>, int <i>stretch</i> = 1)</h3><p>Inserts a stretch of <i>stretch</i> at <i>index</i>, or before any item that is currently at <i>index</i>.</p> <p><b>See also</b> <a href="qgraphicslinearlayout.html#addStretch">addStretch</a>(), <a href="qgraphicslinearlayout.html#setStretchFactor">setStretchFactor</a>(), <a href="qgraphicslinearlayout.html#setItemSpacing">setItemSpacing</a>(), and <a href="qgraphicslinearlayout.html#insertItem">insertItem</a>().</p> <h3 class="fn"><a name="invalidate" />QGraphicsLinearLayout.invalidate (<i>self</i>)</h3><p>Reimplemented from <a href="qgraphicslayout.html#invalidate">QGraphicsLayout.invalidate</a>().</p> <h3 class="fn"><a name="itemAt" /><a href="qgraphicslayoutitem.html">QGraphicsLayoutItem</a> QGraphicsLinearLayout.itemAt (<i>self</i>, int <i>index</i>)</h3><p>Reimplemented from <a href="qgraphicslayout.html#itemAt">QGraphicsLayout.itemAt</a>().</p> <p>When iterating from 0 and up, it will return the items in the visual arranged order.</p> <h3 class="fn"><a name="itemSpacing" />float QGraphicsLinearLayout.itemSpacing (<i>self</i>, int <i>index</i>)</h3><p>Returns the spacing after item at <i>index</i>.</p> <p><b>See also</b> <a href="qgraphicslinearlayout.html#setItemSpacing">setItemSpacing</a>().</p> <h3 class="fn"><a name="orientation" /><a href="qt.html#Orientation-enum">Qt.Orientation</a> QGraphicsLinearLayout.orientation (<i>self</i>)</h3><p>Returns the layout orientation.</p> <p><b>See also</b> <a href="qgraphicslinearlayout.html#setOrientation">setOrientation</a>().</p> <h3 class="fn"><a name="removeAt" />QGraphicsLinearLayout.removeAt (<i>self</i>, int <i>index</i>)</h3><p>Reimplemented from <a href="qgraphicslayout.html#removeAt">QGraphicsLayout.removeAt</a>().</p> <p>Removes the item at <i>index</i> without destroying it. Ownership of the item is transferred to the caller.</p> <p><b>See also</b> <a href="qgraphicslinearlayout.html#removeItem">removeItem</a>() and <a href="qgraphicslinearlayout.html#insertItem">insertItem</a>().</p> <h3 class="fn"><a name="removeItem" />QGraphicsLinearLayout.removeItem (<i>self</i>, <a href="qgraphicslayoutitem.html">QGraphicsLayoutItem</a> <i>item</i>)</h3><p>The <i>item</i> argument</p><p>Removes <i>item</i> from the layout without destroying it. Ownership of <i>item</i> is transferred to the caller.</p> <p><b>See also</b> <a href="qgraphicslinearlayout.html#removeAt">removeAt</a>() and <a href="qgraphicslinearlayout.html#insertItem">insertItem</a>().</p> <h3 class="fn"><a name="setAlignment" />QGraphicsLinearLayout.setAlignment (<i>self</i>, <a href="qgraphicslayoutitem.html">QGraphicsLayoutItem</a> <i>item</i>, <a href="qt-alignment.html">Qt.Alignment</a> <i>alignment</i>)</h3><p>Sets the alignment of <i>item</i> to <i>alignment</i>. If <i>item</i>'s alignment changes, the layout is automatically invalidated.</p> <p><b>See also</b> <a href="qgraphicslinearlayout.html#alignment">alignment</a>() and <a href="qgraphicslinearlayout.html#invalidate">invalidate</a>().</p> <h3 class="fn"><a name="setGeometry" />QGraphicsLinearLayout.setGeometry (<i>self</i>, <a href="qrectf.html">QRectF</a> <i>rect</i>)</h3><p>Reimplemented from <a href="qgraphicslayoutitem.html#setGeometry">QGraphicsLayoutItem.setGeometry</a>().</p> <h3 class="fn"><a name="setItemSpacing" />QGraphicsLinearLayout.setItemSpacing (<i>self</i>, int <i>index</i>, float <i>spacing</i>)</h3><p>Sets the spacing after item at <i>index</i> to <i>spacing</i>.</p> <p><b>See also</b> <a href="qgraphicslinearlayout.html#itemSpacing">itemSpacing</a>().</p> <h3 class="fn"><a name="setOrientation" />QGraphicsLinearLayout.setOrientation (<i>self</i>, <a href="qt.html#Orientation-enum">Qt.Orientation</a> <i>orientation</i>)</h3><p>Change the layout orientation to <i>orientation</i>. Changing the layout orientation will automatically invalidate the layout.</p> <p><b>See also</b> <a href="qgraphicslinearlayout.html#orientation">orientation</a>().</p> <h3 class="fn"><a name="setSpacing" />QGraphicsLinearLayout.setSpacing (<i>self</i>, float <i>spacing</i>)</h3><p>Sets the layout's spacing to <i>spacing</i>. Spacing refers to the vertical and horizontal distances between items.</p> <p><b>See also</b> <a href="qgraphicslinearlayout.html#spacing">spacing</a>(), <a href="qgraphicslinearlayout.html#setItemSpacing">setItemSpacing</a>(), <a href="qgraphicslinearlayout.html#setStretchFactor">setStretchFactor</a>(), and <a href="qgraphicsgridlayout.html#setSpacing">QGraphicsGridLayout.setSpacing</a>().</p> <h3 class="fn"><a name="setStretchFactor" />QGraphicsLinearLayout.setStretchFactor (<i>self</i>, <a href="qgraphicslayoutitem.html">QGraphicsLayoutItem</a> <i>item</i>, int <i>stretch</i>)</h3><p>Sets the stretch factor for <i>item</i> to <i>stretch</i>. If an item's stretch factor changes, this function will invalidate the layout.</p> <p>Setting <i>stretch</i> to 0 removes the stretch factor from the item, and is effectively equivalent to setting <i>stretch</i> to 1.</p> <p><b>See also</b> <a href="qgraphicslinearlayout.html#stretchFactor">stretchFactor</a>().</p> <h3 class="fn"><a name="sizeHint" /><a href="qsizef.html">QSizeF</a> QGraphicsLinearLayout.sizeHint (<i>self</i>, <a href="qt.html#SizeHint-enum">Qt.SizeHint</a> <i>which</i>, <a href="qsizef.html">QSizeF</a> <i>constraint</i> = QSizeF())</h3><p>Reimplemented from <a href="qgraphicslayoutitem.html#sizeHint">QGraphicsLayoutItem.sizeHint</a>().</p> <h3 class="fn"><a name="spacing" />float QGraphicsLinearLayout.spacing (<i>self</i>)</h3><p>Returns the layout's spacing. Spacing refers to the vertical and horizontal distances between items.</p> <p><b>See also</b> <a href="qgraphicslinearlayout.html#setSpacing">setSpacing</a>().</p> <h3 class="fn"><a name="stretchFactor" />int QGraphicsLinearLayout.stretchFactor (<i>self</i>, <a href="qgraphicslayoutitem.html">QGraphicsLayoutItem</a> <i>item</i>)</h3><p>Returns the stretch factor for <i>item</i>. The default stretch factor is 0, meaning that the item has no assigned stretch factor.</p> <p><b>See also</b> <a href="qgraphicslinearlayout.html#setStretchFactor">setStretchFactor</a>().</p> <address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.10.3 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt 4.8.5</td></tr></table></div></address></body></html>