<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Unable to contain children bounding boxes in parent bounding box programatically.  Screenshots...]]></title><description><![CDATA[<p dir="auto"><a href="https://postimg.org/image/ixb304fi9/" target="_blank" rel="noopener noreferrer nofollow ugc">https://postimg.org/image/ixb304fi9/</a></p>
<p dir="auto">Here's the code.  As you can see in the screen shots, bottom and right adjust in size properly, but placing a node in the top-left area such that the node extents outside the parent, no size adjustment is made, the box and that size seems to stay the same.  I've tried 100 different code variants and spent 2 days on the problem.</p>
<pre><code>class RoundedRectNodeGfx(NodeGfx, QGraphicsRectItem):
    def __init__(self, obj, parent=None):
        QGraphicsRectItem.__init__(self, parent)
        NodeGfx.__init__(self, obj)
        self.setRect(QRectF(0,0,100,100))
        # TODO DEBUG REMOVE:
        self.setBrush(QBrush(QColor(255, 255, 0, 255)))
        self.setPen(QPen(QColor(0, 255, 255, 255), 2.5))
        
    def paint(self, painter, item, widget):
        GfxObject.paint(self, painter, item, widget)
        painter.setPen(self.pen())
        painter.setBrush(self.brush())
        painter.drawRect(self.rect())
        # DBG
        self._dbgPaint(painter, item, widget)
        
    def resize(self, children=None):
        if children == None:
            children = self.childItems()
        rects = [child.mapToItem(self, QPolygonF(child.rect())).boundingRect() for child in children]
        rects.append(self.boundingRect())
        rect = minBoundingRect(rects)
        #self.setPos_(self.sceneTransform().map(rect.topLeft()))
        #rect = self.mapFromScene(rect).boundingRect()
        pos = self.sceneTransform().map(rect.topLeft())
        self.setPos_(pos)
        self.setRect(QRectF(0,0, rect.width(), rect.height()))        
        parent = self.parentItem()
        if parent and isinstance(parent, NodeGfx):
            parent.resize(children=[self])

    #def selectionPath(self):
        #pass
    
    #def sceneBoundingPolygon(self):
        #return self.sceneTransform().map(QPolygonF(self.boundingRect()))
</code></pre>
]]></description><link>https://forum.qt.io/topic/69812/unable-to-contain-children-bounding-boxes-in-parent-bounding-box-programatically-screenshots</link><generator>RSS for Node</generator><lastBuildDate>Fri, 18 Sep 2026 12:38:31 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/69812.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 31 Jul 2016 17:11:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Unable to contain children bounding boxes in parent bounding box programatically.  Screenshots... on Sun, 31 Jul 2016 23:11:38 GMT]]></title><description><![CDATA[<p dir="auto">This variant does not work either:</p>
<pre><code>    def resize(self, children=None):
        if children == None:
            children = self.childItems()        
        sceneRect = self.sceneBoundingRect()
        childItems = self.scene().createItemGroup(children)
        childSceneRect = childItems.sceneBoundingRect()
        self._dbgPolys['child scene rect'] = lambda: QPolygonF(childSceneRect)
        rect = minBoundingRect([childSceneRect, sceneRect])
        self.setPos_(rect.topLeft())
        #rect = self.sceneTransform().inverted()[0].map(QPolygonF(rect)).boundingRect()
        self.setRect(QRectF(0,0, rect.width(), rect.height()))
        parent = self.parentItem()
        if parent and isinstance(parent, NodeGfx):
            parent.resize(children=[self])
</code></pre>
]]></description><link>https://forum.qt.io/post/340158</link><guid isPermaLink="true">https://forum.qt.io/post/340158</guid><dc:creator><![CDATA[enjoysmath]]></dc:creator><pubDate>Sun, 31 Jul 2016 23:11:38 GMT</pubDate></item></channel></rss>