NodeContainment.jpg

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.

Qt Code:
  1. class RoundedRectNodeGfx(NodeGfx, QGraphicsRectItem):
  2. def __init__(self, obj, parent=None):
  3. QGraphicsRectItem.__init__(self, parent)
  4. NodeGfx.__init__(self, obj)
  5. self.setRect(QRectF(0,0,100,100))
  6. # TODO DEBUG REMOVE:
  7. self.setBrush(QBrush(QColor(255, 255, 0, 255)))
  8. self.setPen(QPen(QColor(0, 255, 255, 255), 2.5))
  9.  
  10. def paint(self, painter, item, widget):
  11. GfxObject.paint(self, painter, item, widget)
  12. painter.setPen(self.pen())
  13. painter.setBrush(self.brush())
  14. painter.drawRect(self.rect())
  15. # DBG
  16. self._dbgPaint(painter, item, widget)
  17.  
  18. def resize(self, children=None):
  19. if children == None:
  20. children = self.childItems()
  21. rects = [child.mapToItem(self, QPolygonF(child.rect())).boundingRect() for child in children]
  22. rects.append(self.boundingRect())
  23. rect = minBoundingRect(rects)
  24. #self.setPos_(self.sceneTransform().map(rect.topLeft()))
  25. #rect = self.mapFromScene(rect).boundingRect()
  26. pos = self.sceneTransform().map(rect.topLeft())
  27. self.setPos_(pos)
  28. self.setRect(QRectF(0,0, rect.width(), rect.height()))
  29. parent = self.parentItem()
  30. if parent and isinstance(parent, NodeGfx):
  31. parent.resize(children=[self])
  32.  
  33. #def selectionPath(self):
  34. #pass
  35.  
  36. #def sceneBoundingPolygon(self):
  37. #return self.sceneTransform().map(QPolygonF(self.boundingRect()))
To copy to clipboard, switch view to plain text mode