<?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>QGraphicsItemGroup 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">QGraphicsItemGroup Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QGraphicsItemGroup class provides a container that treats a group of items as a single item. <a href="#details">More...</a></p> <p>Inherits <a href="qgraphicsitem.html">QGraphicsItem</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qgraphicsitemgroup.html#QGraphicsItemGroup">__init__</a></b> (<i>self</i>, QGraphicsItem <i>parent</i> = None, QGraphicsScene <i>scene</i> = None)</li><li><div class="fn" /><b><a href="qgraphicsitemgroup.html#addToGroup">addToGroup</a></b> (<i>self</i>, QGraphicsItem <i>item</i>)</li><li><div class="fn" />QRectF <b><a href="qgraphicsitemgroup.html#boundingRect">boundingRect</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qgraphicsitemgroup.html#isObscuredBy">isObscuredBy</a></b> (<i>self</i>, QGraphicsItem <i>item</i>)</li><li><div class="fn" />QPainterPath <b><a href="qgraphicsitemgroup.html#opaqueArea">opaqueArea</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qgraphicsitemgroup.html#paint">paint</a></b> (<i>self</i>, QPainter <i>painter</i>, QStyleOptionGraphicsItem <i>option</i>, QWidget <i>widget</i> = None)</li><li><div class="fn" /><b><a href="qgraphicsitemgroup.html#removeFromGroup">removeFromGroup</a></b> (<i>self</i>, QGraphicsItem <i>item</i>)</li><li><div class="fn" />int <b><a href="qgraphicsitemgroup.html#type">type</a></b> (<i>self</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QGraphicsItemGroup class provides a container that treats a group of items as a single item.</p> <p>A QGraphicsItemGroup is a special type of compound item that treats itself and all its children as one item (i.e., all events and geometries for all children are merged together). It's common to use item groups in presentation tools, when the user wants to group several smaller items into one big item in order to simplify moving and copying of items.</p> <p>If all you want is to store items inside other items, you can use any <a href="qgraphicsitem.html">QGraphicsItem</a> directly by passing a suitable parent to <a href="qgraphicsitem.html#setParentItem">setParentItem</a>().</p> <p>The <a href="qgraphicsitemgroup.html#boundingRect">boundingRect</a>() function of QGraphicsItemGroup returns the bounding rectangle of all items in the item group. QGraphicsItemGroup ignores the <a href="qgraphicsitem.html#GraphicsItemFlag-enum">ItemIgnoresTransformations</a> flag on its children (i.e., with respect to the geometry of the group item, the children are treated as if they were transformable).</p> <p>There are two ways to construct an item group. The easiest and most common approach is to pass a list of items (e.g., all selected items) to <a href="qgraphicsscene.html#createItemGroup">QGraphicsScene.createItemGroup</a>(), which returns a new QGraphicsItemGroup item. The other approach is to manually construct a QGraphicsItemGroup item, add it to the scene calling <a href="qgraphicsscene.html#addItem">QGraphicsScene.addItem</a>(), and then add items to the group manually, one at a time by calling <a href="qgraphicsitemgroup.html#addToGroup">addToGroup</a>(). To dismantle ("ungroup") an item group, you can either call <a href="qgraphicsscene.html#destroyItemGroup">QGraphicsScene.destroyItemGroup</a>(), or you can manually remove all items from the group by calling <a href="qgraphicsitemgroup.html#removeFromGroup">removeFromGroup</a>().</p> <pre class="cpp"> <span class="comment">// Group all selected items together</span> <span class="type">QGraphicsItemGroup</span> <span class="operator">*</span>group <span class="operator">=</span> scene<span class="operator">-</span><span class="operator">></span>createItemGroup(scene<span class="operator">-</span><span class="operator">></span>selecteditems()); <span class="comment">// Destroy the group, and delete the group item</span> scene<span class="operator">-</span><span class="operator">></span>destroyItemGroup(group); </pre> <p>The operation of adding and removing items preserves the items' scene-relative position and transformation, as opposed to calling <a href="qgraphicsitem.html#setParentItem">setParentItem</a>(), where only the child item's parent-relative position and transformation are kept.</p> <p>The addtoGroup() function reparents the target item to this item group, keeping the item's position and transformation intact relative to the scene. Visually, this means that items added via <a href="qgraphicsitemgroup.html#addToGroup">addToGroup</a>() will remain completely unchanged as a result of this operation, regardless of the item or the group's current position or transformation; although the item's position and matrix are likely to change.</p> <p>The <a href="qgraphicsitemgroup.html#removeFromGroup">removeFromGroup</a>() function has similar semantics to <a href="qgraphicsitem.html#setParentItem">setParentItem</a>(); it reparents the item to the parent item of the item group. As with <a href="qgraphicsitemgroup.html#addToGroup">addToGroup</a>(), the item's scene-relative position and transformation remain intact.</p> <hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QGraphicsItemGroup" />QGraphicsItemGroup.__init__ (<i>self</i>, <a href="qgraphicsitem.html">QGraphicsItem</a> <i>parent</i> = None, <a href="qgraphicsscene.html">QGraphicsScene</a> <i>scene</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>The <i>scene</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a <a href="qgraphicsitemgroup.html">QGraphicsItemGroup</a>. <i>parent</i> is passed to <a href="qgraphicsitem.html">QGraphicsItem</a>'s constructor.</p> <p><b>See also</b> <a href="qgraphicsscene.html#addItem">QGraphicsScene.addItem</a>().</p> <h3 class="fn"><a name="addToGroup" />QGraphicsItemGroup.addToGroup (<i>self</i>, <a href="qgraphicsitem.html">QGraphicsItem</a> <i>item</i>)</h3><p>The <i>item</i> argument has it's ownership transferred to Qt.</p><p>Adds the given <i>item</i> and item's child items to this item group. The item and child items will be reparented to this group, but its position and transformation relative to the scene will stay intact.</p> <p><b>See also</b> <a href="qgraphicsitemgroup.html#removeFromGroup">removeFromGroup</a>() and <a href="qgraphicsscene.html#createItemGroup">QGraphicsScene.createItemGroup</a>().</p> <h3 class="fn"><a name="boundingRect" /><a href="qrectf.html">QRectF</a> QGraphicsItemGroup.boundingRect (<i>self</i>)</h3><p>Reimplemented from <a href="qgraphicsitem.html#boundingRect">QGraphicsItem.boundingRect</a>().</p> <p>Returns the bounding rect of this group item, and all its children.</p> <h3 class="fn"><a name="isObscuredBy" />bool QGraphicsItemGroup.isObscuredBy (<i>self</i>, <a href="qgraphicsitem.html">QGraphicsItem</a> <i>item</i>)</h3><p>Reimplemented from <a href="qgraphicsitem.html#isObscuredBy">QGraphicsItem.isObscuredBy</a>().</p> <h3 class="fn"><a name="opaqueArea" /><a href="qpainterpath.html">QPainterPath</a> QGraphicsItemGroup.opaqueArea (<i>self</i>)</h3><p>Reimplemented from <a href="qgraphicsitem.html#opaqueArea">QGraphicsItem.opaqueArea</a>().</p> <h3 class="fn"><a name="paint" />QGraphicsItemGroup.paint (<i>self</i>, <a href="qpainter.html">QPainter</a> <i>painter</i>, <a href="qstyleoptiongraphicsitem.html">QStyleOptionGraphicsItem</a> <i>option</i>, <a href="qwidget.html">QWidget</a> <i>widget</i> = None)</h3><p>Reimplemented from <a href="qgraphicsitem.html#paint">QGraphicsItem.paint</a>().</p> <h3 class="fn"><a name="removeFromGroup" />QGraphicsItemGroup.removeFromGroup (<i>self</i>, <a href="qgraphicsitem.html">QGraphicsItem</a> <i>item</i>)</h3><p>Removes the specified <i>item</i> from this group. The item will be reparented to this group's parent item, or to 0 if this group has no parent. Its position and transformation relative to the scene will stay intact.</p> <p><b>See also</b> <a href="qgraphicsitemgroup.html#addToGroup">addToGroup</a>() and <a href="qgraphicsscene.html#destroyItemGroup">QGraphicsScene.destroyItemGroup</a>().</p> <h3 class="fn"><a name="type" />int QGraphicsItemGroup.type (<i>self</i>)</h3><p>Reimplemented from <a href="qgraphicsitem.html#type">QGraphicsItem.type</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>