Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Unable to contain children bounding boxes in parent bounding box programatically. Screenshots...
Qt 6.11 is out! See what's new in the release blog

Unable to contain children bounding boxes in parent bounding box programatically. Screenshots...

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 833 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • enjoysmathE Offline
    enjoysmathE Offline
    enjoysmath
    wrote on last edited by
    #1

    https://postimg.org/image/ixb304fi9/

    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.

    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()))
    

    https://github.com/enjoysmath
    https://math.stackexchange.com/users/26327/exercisingmathematician

    1 Reply Last reply
    0
    • enjoysmathE Offline
      enjoysmathE Offline
      enjoysmath
      wrote on last edited by
      #2

      This variant does not work either:

          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])
      

      https://github.com/enjoysmath
      https://math.stackexchange.com/users/26327/exercisingmathematician

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved