Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QGraphicsLayout does not expand like QLayouts
Forum Updated to NodeBB v4.3 + New Features

QGraphicsLayout does not expand like QLayouts

Scheduled Pinned Locked Moved Solved Qt for Python
2 Posts 2 Posters 518 Views
  • 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.
  • NiagarerN Offline
    NiagarerN Offline
    Niagarer
    wrote on last edited by Niagarer
    #1

    Hi

    70923838-0f31-4ce9-a3e7-5ff87f70974a-grafik.png
    I am using some QGraphicsLinearLayouts here and want them to always scale to the max, adding space between the contents (which is what a normal QLayout does). Shouldn't this be done via the size policy?

    In this example:
    The text at the top is the title label (QGraphicsLayoutItem, QGraphicsItem). The box beneath it is the body (a QGraphicsLinearLayout holding two other linear layouts, one for inputs, one for outputs). Title label and body layout are together in a vertical linear layout. Here, the min title width is larger than the min body width, so the body layout should scale to that width, keeping its contents at the edges left and right. Same with the outputs layout of the body here. The right labels in the picture should be positioned at the top, middle, and the third at the bottom of the body layout.
    I tried setting the size policy of the layouts to Maximum or Expanding, both didn't work. I am sure this is basic, but I don't get it.
    This is how I create the layouts:

    class NodeInstance(QGraphicsItem):
        def __init__(self):
            super(NodeInstance, self).__init__()
    
            self.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsMovable |
                          QGraphicsItem.ItemSendsScenePositionChanges)
            self.setAcceptHoverEvents(True)
    
            self.title = TitleLabel()  # TitleLabel(QGraphicsLayoutItem, QGraphicsItem)
    
    
            # CONTENT WIDGET AND LAYOUTS
            self.contents_widget = QGraphicsWidget(self)
            self.contents_layout = QGraphicsLinearLayout(Qt.Vertical)
            self.contents_layout.setSpacing(10)
    
    
            #   TITLE
            self.contents_layout.addItem(self.title)
    
    
            #   BODY
            self.body_layout = QGraphicsLinearLayout(Qt.Horizontal)
            self.body_layout.setSpacing(30)
            self.body_layout.setSizePolicy(QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum))
    
            #   add inputs
            self.inputs_layout = QGraphicsLinearLayout(Qt.Vertical)
            for i in range(5):
                inp = InputPortInstance()  # InputPortInstance(QGraphicsLinearLayout) - holds circle and label, see picture
                self.inputs_layout.addItem(inp)
            self.body_layout.addItem(self.inputs_layout)
            self.body_layout.setAlignment(self.inputs_layout, Qt.AlignLeft | Qt.AlignVCenter)
    
            #   add outputs
            self.outputs_layout = QGraphicsLinearLayout(Qt.Vertical)
            for i in range(3):
                out = OutputPortInstance()  # OutputPortInstance(QGraphicsLinearLayout) - holds circle and label, see picture
                self.outputs_layout.addItem(out)
            self.body_layout.addItem(self.outputs_layout)
            self.body_layout.setAlignment(self.outputs_layout, Qt.AlignRight | Qt.AlignVCenter)
    
            self.contents_layout.addItem(self.body_layout)
    
    
            self.contents_widget.setLayout(self.contents_layout)
    
    ...
    

    Thanks for answers!

    1 Reply Last reply
    0
    • NiagarerN Offline
      NiagarerN Offline
      Niagarer
      wrote on last edited by
      #2

      I've found a solution I guess. It's weird though.
      I had to add

      layout.addStretch()
      

      between adding two layouts.
      There is so much about these layouts that just does not seem to work. Removing an item: still visible and the layout doesn't adjust it's size. Deleting the item: still visible (!?). Setting a SizePolicy: no effect at all (basically counts for everything size-related). And a lot of other small things that make me wonder. I probably just don't get it.

      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