<?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>QGraphicsAnchorLayout 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">QGraphicsAnchorLayout Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QGraphicsAnchorLayout class provides a layout where one can anchor widgets together 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="qgraphicsanchorlayout.html#QGraphicsAnchorLayout">__init__</a></b> (<i>self</i>, QGraphicsLayoutItem <i>parent</i> = None)</li><li><div class="fn" />QGraphicsAnchor <b><a href="qgraphicsanchorlayout.html#addAnchor">addAnchor</a></b> (<i>self</i>, QGraphicsLayoutItem <i>firstItem</i>, Qt.AnchorPoint <i>firstEdge</i>, QGraphicsLayoutItem <i>secondItem</i>, Qt.AnchorPoint <i>secondEdge</i>)</li><li><div class="fn" /><b><a href="qgraphicsanchorlayout.html#addAnchors">addAnchors</a></b> (<i>self</i>, QGraphicsLayoutItem <i>firstItem</i>, QGraphicsLayoutItem <i>secondItem</i>, Qt.Orientations <i>orientations</i> = Qt.Horizontal|Qt.Vertical)</li><li><div class="fn" /><b><a href="qgraphicsanchorlayout.html#addCornerAnchors">addCornerAnchors</a></b> (<i>self</i>, QGraphicsLayoutItem <i>firstItem</i>, Qt.Corner <i>firstCorner</i>, QGraphicsLayoutItem <i>secondItem</i>, Qt.Corner <i>secondCorner</i>)</li><li><div class="fn" />QGraphicsAnchor <b><a href="qgraphicsanchorlayout.html#anchor">anchor</a></b> (<i>self</i>, QGraphicsLayoutItem <i>firstItem</i>, Qt.AnchorPoint <i>firstEdge</i>, QGraphicsLayoutItem <i>secondItem</i>, Qt.AnchorPoint <i>secondEdge</i>)</li><li><div class="fn" />int <b><a href="qgraphicsanchorlayout.html#count">count</a></b> (<i>self</i>)</li><li><div class="fn" />float <b><a href="qgraphicsanchorlayout.html#horizontalSpacing">horizontalSpacing</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qgraphicsanchorlayout.html#invalidate">invalidate</a></b> (<i>self</i>)</li><li><div class="fn" />QGraphicsLayoutItem <b><a href="qgraphicsanchorlayout.html#itemAt">itemAt</a></b> (<i>self</i>, int <i>index</i>)</li><li><div class="fn" /><b><a href="qgraphicsanchorlayout.html#removeAt">removeAt</a></b> (<i>self</i>, int <i>index</i>)</li><li><div class="fn" /><b><a href="qgraphicsanchorlayout.html#setGeometry">setGeometry</a></b> (<i>self</i>, QRectF <i>rect</i>)</li><li><div class="fn" /><b><a href="qgraphicsanchorlayout.html#setHorizontalSpacing">setHorizontalSpacing</a></b> (<i>self</i>, float <i>spacing</i>)</li><li><div class="fn" /><b><a href="qgraphicsanchorlayout.html#setSpacing">setSpacing</a></b> (<i>self</i>, float <i>spacing</i>)</li><li><div class="fn" /><b><a href="qgraphicsanchorlayout.html#setVerticalSpacing">setVerticalSpacing</a></b> (<i>self</i>, float <i>spacing</i>)</li><li><div class="fn" />QSizeF <b><a href="qgraphicsanchorlayout.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="qgraphicsanchorlayout.html#verticalSpacing">verticalSpacing</a></b> (<i>self</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QGraphicsAnchorLayout class provides a layout where one can anchor widgets together in Graphics View.</p> <p>The anchor layout allows developers to specify how widgets should be placed relative to each other, and to the layout itself. The specification is made by adding anchors to the layout by calling <a href="qgraphicsanchorlayout.html#addAnchor">addAnchor</a>(), <a href="qgraphicsanchorlayout.html#addAnchors">addAnchors</a>() or <a href="qgraphicsanchorlayout.html#addCornerAnchors">addCornerAnchors</a>().</p> <p>Existing anchors in the layout can be accessed with the <a href="qgraphicsanchorlayout.html#anchor">anchor</a>() function. Items that are anchored are automatically added to the layout, and if items are removed, all their anchors will be automatically removed.</p> <div class="float-left"> <p><img alt="Using an anchor layout to align simple colored widgets." src="images/simpleanchorlayout-example.png" /></p> </div> <p>Anchors are always set up between edges of an item, where the "center" is also considered to be an edge. Consider the following example:</p> <pre class="cpp"> layout<span class="operator">-</span><span class="operator">></span>addAnchor(b<span class="operator">,</span> <span class="type"><a href="qt.html">Qt</a></span><span class="operator">.</span>AnchorLeft<span class="operator">,</span> a<span class="operator">,</span> <span class="type"><a href="qt.html">Qt</a></span><span class="operator">.</span>AnchorRight); layout<span class="operator">-</span><span class="operator">></span>addAnchor(b<span class="operator">,</span> <span class="type"><a href="qt.html">Qt</a></span><span class="operator">.</span>AnchorTop<span class="operator">,</span> a<span class="operator">,</span> <span class="type"><a href="qt.html">Qt</a></span><span class="operator">.</span>AnchorBottom); </pre> <p>Here, the right edge of item <tt>a</tt> is anchored to the left edge of item <tt>b</tt> and the bottom edge of item <tt>a</tt> is anchored to the top edge of item <tt>b</tt>, with the result that item <tt>b</tt> will be placed diagonally to the right and below item <tt>b</tt>.</p> <p>The <a href="qgraphicsanchorlayout.html#addCornerAnchors">addCornerAnchors</a>() function provides a simpler way of anchoring the corners of two widgets than the two individual calls to <a href="qgraphicsanchorlayout.html#addAnchor">addAnchor</a>() shown in the code above. Here, we see how a widget can be anchored to the top-left corner of the enclosing layout:</p> <pre class="cpp"> layout<span class="operator">-</span><span class="operator">></span>addCornerAnchors(a<span class="operator">,</span> <span class="type"><a href="qt.html">Qt</a></span><span class="operator">.</span>TopLeftCorner<span class="operator">,</span> layout<span class="operator">,</span> <span class="type"><a href="qt.html">Qt</a></span><span class="operator">.</span>TopLeftCorner); </pre> <p>In cases where anchors are used to match the widths or heights of widgets, it is convenient to use the <a href="qgraphicsanchorlayout.html#addAnchors">addAnchors</a>() function. As with the other functions for specifying anchors, it can also be used to anchor a widget to a layout.</p> <br style="clear: both" /> <a id="size-hints-and-size-policies-in-an-anchor-layout" name="size-hints-and-size-policies-in-an-anchor-layout" /> <h3>Size Hints and Size Policies in an Anchor Layout</h3> <p>QGraphicsAnchorLayout respects each item's size hints and size policies. Note that there are some properties of <a href="qsizepolicy.html">QSizePolicy</a> that are <a href="known-issues.html">not respected</a>.</p> <a id="spacing-within-an-anchor-layout" name="spacing-within-an-anchor-layout" /> <h3>Spacing within an Anchor Layout</h3> <p>The layout may distribute some space between the items. If the spacing has not been explicitly specified, the actual amount of space will usually be 0.</p> <p>However, if the first edge is the <i>opposite</i> of the second edge (e.g., the right edge of the first widget is anchored to the left edge of the second widget), the size of the anchor will be queried from the style through a pixel metric: <a href="qstyle.html#PixelMetric-enum">PM_LayoutHorizontalSpacing</a> for horizontal anchors and <a href="qstyle.html#PixelMetric-enum">PM_LayoutVerticalSpacing</a> for vertical anchors.</p> <p>If the spacing is negative, the items will overlap to some extent.</p> <a id="known-issues" name="known-issues" /> <h3>Known issues</h3> <p>There are some features that QGraphicsAnchorLayout currently does not support. This might change in the future, so avoid using these features if you want to avoid any future regressions in behaviour:</p> <ul> <li>Stretch factors are not respected.</li> <li><a href="qsizepolicy.html#PolicyFlag-enum">QSizePolicy.ExpandFlag</a> is not respected.</li> <li>Height for width is not respected.</li> </ul> <hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QGraphicsAnchorLayout" />QGraphicsAnchorLayout.__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="qgraphicsanchorlayout.html">QGraphicsAnchorLayout</a> instance. <i>parent</i> is passed to <a href="qgraphicslayout.html">QGraphicsLayout</a>'s constructor.</p> <h3 class="fn"><a name="addAnchor" /><a href="qgraphicsanchor.html">QGraphicsAnchor</a> QGraphicsAnchorLayout.addAnchor (<i>self</i>, <a href="qgraphicslayoutitem.html">QGraphicsLayoutItem</a> <i>firstItem</i>, <a href="qt.html#AnchorPoint-enum">Qt.AnchorPoint</a> <i>firstEdge</i>, <a href="qgraphicslayoutitem.html">QGraphicsLayoutItem</a> <i>secondItem</i>, <a href="qt.html#AnchorPoint-enum">Qt.AnchorPoint</a> <i>secondEdge</i>)</h3><p>The <i>firstItem</i> argument has it's ownership transferred to Qt.</p><p>The <i>secondItem</i> argument has it's ownership transferred to Qt.</p><p>Creates an anchor between the edge <i>firstEdge</i> of item <i>firstItem</i> and the edge <i>secondEdge</i> of item <i>secondItem</i>. The spacing of the anchor is picked up from the style. Anchors between a layout edge and an item edge will have a size of 0. If there is already an anchor between the edges, the the new anchor will replace the old one.</p> <p><i>firstItem</i> and <i>secondItem</i> are automatically added to the layout if they are not part of the layout. This means that <a href="qgraphicsanchorlayout.html#count">count</a>() can increase by up to 2.</p> <p>The spacing an anchor will get depends on the type of anchor. For instance, anchors from the Right edge of one item to the Left edge of another (or vice versa) will use the default horizontal spacing. The same behaviour applies to Bottom to Top anchors, (but they will use the default vertical spacing). For all other anchor combinations, the spacing will be 0. All anchoring functions will follow this rule.</p> <p>The spacing can also be set manually by using <a href="qgraphicsanchor.html#spacing-prop">QGraphicsAnchor.setSpacing</a>() method.</p> <p>Calling this function where <i>firstItem</i> or <i>secondItem</i> are ancestors of the layout have undefined behaviour.</p> <p><b>See also</b> <a href="qgraphicsanchorlayout.html#addAnchors">addAnchors</a>() and <a href="qgraphicsanchorlayout.html#addCornerAnchors">addCornerAnchors</a>().</p> <h3 class="fn"><a name="addAnchors" />QGraphicsAnchorLayout.addAnchors (<i>self</i>, <a href="qgraphicslayoutitem.html">QGraphicsLayoutItem</a> <i>firstItem</i>, <a href="qgraphicslayoutitem.html">QGraphicsLayoutItem</a> <i>secondItem</i>, <a href="qt-orientations.html">Qt.Orientations</a> <i>orientations</i> = Qt.Horizontal|Qt.Vertical)</h3><p>The <i>firstItem</i> argument has it's ownership transferred to Qt.</p><p>The <i>secondItem</i> argument has it's ownership transferred to Qt.</p><p>Anchors two or four edges of <i>firstItem</i> with the corresponding edges of <i>secondItem</i>, so that <i>firstItem</i> has the same size as <i>secondItem</i> in the dimensions specified by <i>orientations</i>.</p> <p>For example, the following example anchors the left and right edges of two items to match their widths:</p> <pre class="cpp"> layout->addAnchor(b, Qt.AnchorLeft, c, Qt.AnchorLeft); layout->addAnchor(b, Qt.AnchorRight, c, Qt.AnchorRight); </pre> <p>This can also be achieved using the following line of code:</p> <pre class="cpp"> layout<span class="operator">-</span><span class="operator">></span>addAnchors(b<span class="operator">,</span> c<span class="operator">,</span> <span class="type"><a href="qt.html">Qt</a></span><span class="operator">.</span>Horizontal); </pre> <p><b>See also</b> <a href="qgraphicsanchorlayout.html#addAnchor">addAnchor</a>() and <a href="qgraphicsanchorlayout.html#addCornerAnchors">addCornerAnchors</a>().</p> <h3 class="fn"><a name="addCornerAnchors" />QGraphicsAnchorLayout.addCornerAnchors (<i>self</i>, <a href="qgraphicslayoutitem.html">QGraphicsLayoutItem</a> <i>firstItem</i>, <a href="qt.html#Corner-enum">Qt.Corner</a> <i>firstCorner</i>, <a href="qgraphicslayoutitem.html">QGraphicsLayoutItem</a> <i>secondItem</i>, <a href="qt.html#Corner-enum">Qt.Corner</a> <i>secondCorner</i>)</h3><p>The <i>firstItem</i> argument has it's ownership transferred to Qt.</p><p>The <i>secondItem</i> argument has it's ownership transferred to Qt.</p><p>Creates two anchors between <i>firstItem</i> and <i>secondItem</i> specified by the corners, <i>firstCorner</i> and <i>secondCorner</i>, where one is for the horizontal edge and another one for the vertical edge.</p> <p>This is a convenience function, since anchoring corners can be expressed as anchoring two edges. For instance:</p> <pre class="cpp"> layout->addAnchor(a, Qt.AnchorTop, layout, Qt.AnchorTop); layout->addAnchor(a, Qt.AnchorLeft, layout, Qt.AnchorLeft); </pre> <p>This can also be achieved with the following line of code:</p> <pre class="cpp"> layout<span class="operator">-</span><span class="operator">></span>addCornerAnchors(a<span class="operator">,</span> <span class="type"><a href="qt.html">Qt</a></span><span class="operator">.</span>TopLeftCorner<span class="operator">,</span> layout<span class="operator">,</span> <span class="type"><a href="qt.html">Qt</a></span><span class="operator">.</span>TopLeftCorner); </pre> <p>If there is already an anchor between the edge pairs, it will be replaced by the anchors that this function specifies.</p> <p><i>firstItem</i> and <i>secondItem</i> are automatically added to the layout if they are not part of the layout. This means that <a href="qgraphicsanchorlayout.html#count">count</a>() can increase by up to 2.</p> <p><b>See also</b> <a href="qgraphicsanchorlayout.html#addAnchor">addAnchor</a>() and <a href="qgraphicsanchorlayout.html#addAnchors">addAnchors</a>().</p> <h3 class="fn"><a name="anchor" /><a href="qgraphicsanchor.html">QGraphicsAnchor</a> QGraphicsAnchorLayout.anchor (<i>self</i>, <a href="qgraphicslayoutitem.html">QGraphicsLayoutItem</a> <i>firstItem</i>, <a href="qt.html#AnchorPoint-enum">Qt.AnchorPoint</a> <i>firstEdge</i>, <a href="qgraphicslayoutitem.html">QGraphicsLayoutItem</a> <i>secondItem</i>, <a href="qt.html#AnchorPoint-enum">Qt.AnchorPoint</a> <i>secondEdge</i>)</h3><p>Returns the anchor between the anchor points defined by <i>firstItem</i> and <i>firstEdge</i> and <i>secondItem</i> and <i>secondEdge</i>. If there is no such anchor, the function will return 0.</p> <h3 class="fn"><a name="count" />int QGraphicsAnchorLayout.count (<i>self</i>)</h3><p>Reimplemented from <a href="qgraphicslayout.html#count">QGraphicsLayout.count</a>().</p> <h3 class="fn"><a name="horizontalSpacing" />float QGraphicsAnchorLayout.horizontalSpacing (<i>self</i>)</h3><p>Returns the default horizontal spacing for the anchor layout.</p> <p><b>See also</b> <a href="qgraphicsanchorlayout.html#verticalSpacing">verticalSpacing</a>() and <a href="qgraphicsanchorlayout.html#setHorizontalSpacing">setHorizontalSpacing</a>().</p> <h3 class="fn"><a name="invalidate" />QGraphicsAnchorLayout.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> QGraphicsAnchorLayout.itemAt (<i>self</i>, int <i>index</i>)</h3><p>Reimplemented from <a href="qgraphicslayout.html#itemAt">QGraphicsLayout.itemAt</a>().</p> <h3 class="fn"><a name="removeAt" />QGraphicsAnchorLayout.removeAt (<i>self</i>, int <i>index</i>)</h3><p>Reimplemented from <a href="qgraphicslayout.html#removeAt">QGraphicsLayout.removeAt</a>().</p> <p>Removes the layout item at <i>index</i> without destroying it. Ownership of the item is transferred to the caller.</p> <p>Removing an item will also remove any of the anchors associated with it.</p> <p><b>See also</b> <a href="qgraphicsanchorlayout.html#itemAt">itemAt</a>() and <a href="qgraphicsanchorlayout.html#count">count</a>().</p> <h3 class="fn"><a name="setGeometry" />QGraphicsAnchorLayout.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="setHorizontalSpacing" />QGraphicsAnchorLayout.setHorizontalSpacing (<i>self</i>, float <i>spacing</i>)</h3><p>Sets the default horizontal spacing for the anchor layout to <i>spacing</i>.</p> <p><b>See also</b> <a href="qgraphicsanchorlayout.html#horizontalSpacing">horizontalSpacing</a>(), <a href="qgraphicsanchorlayout.html#setVerticalSpacing">setVerticalSpacing</a>(), and <a href="qgraphicsanchorlayout.html#setSpacing">setSpacing</a>().</p> <h3 class="fn"><a name="setSpacing" />QGraphicsAnchorLayout.setSpacing (<i>self</i>, float <i>spacing</i>)</h3><p>Sets the default horizontal and the default vertical spacing for the anchor layout to <i>spacing</i>.</p> <p>If an item is anchored with no spacing associated with the anchor, it will use the default spacing.</p> <p><a href="qgraphicsanchorlayout.html">QGraphicsAnchorLayout</a> does not support negative spacings. Setting a negative value will unset the previous spacing and make the layout use the spacing provided by the current widget style.</p> <p><b>See also</b> <a href="qgraphicsanchorlayout.html#setHorizontalSpacing">setHorizontalSpacing</a>() and <a href="qgraphicsanchorlayout.html#setVerticalSpacing">setVerticalSpacing</a>().</p> <h3 class="fn"><a name="setVerticalSpacing" />QGraphicsAnchorLayout.setVerticalSpacing (<i>self</i>, float <i>spacing</i>)</h3><p>Sets the default vertical spacing for the anchor layout to <i>spacing</i>.</p> <p><b>See also</b> <a href="qgraphicsanchorlayout.html#verticalSpacing">verticalSpacing</a>(), <a href="qgraphicsanchorlayout.html#setHorizontalSpacing">setHorizontalSpacing</a>(), and <a href="qgraphicsanchorlayout.html#setSpacing">setSpacing</a>().</p> <h3 class="fn"><a name="sizeHint" /><a href="qsizef.html">QSizeF</a> QGraphicsAnchorLayout.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="verticalSpacing" />float QGraphicsAnchorLayout.verticalSpacing (<i>self</i>)</h3><p>Returns the default vertical spacing for the anchor layout.</p> <p><b>See also</b> <a href="qgraphicsanchorlayout.html#horizontalSpacing">horizontalSpacing</a>() and <a href="qgraphicsanchorlayout.html#setVerticalSpacing">setVerticalSpacing</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>