title: PyQt5: Creating a flow layout that forces a fixed height
body: <p>I'm trying to make a flow layout effect where the user can modify the width of the widget, and the size adjusts to compensate. I've looked into creating a custom layout, but the layout never increases the height to compensate for a shrinking width. </p>
  
  <p>The best solution I could come up with is setting the height manually on resize, but in PyQt5 this seems to (if you rapidly try to resize the window) lock the entire window, so you cannot resize it or move it any more. It can be resized or moved programatically, but the window no longer responds to user resize/move requests. </p>
  
  <p>It <em>seems</em> like a recursion error, but I can't find any recursive events being triggered, and the rest of the UI doesn't hang, just the resizing.</p>
  
  <p>Here is my use case:</p>
  
  <pre><code>import random
  import sys
  import math
  
  from PyQt5.QtGui import QPalette, QColor
  from PyQt5.QtWidgets import QWidget, QApplication
  
  
  class ChangingHeightWidget(QWidget):
      def __init__(self, *args, **kwargs):
          super().__init__(*args, **kwargs)
          self._allow_height_change = False
          self._child_widgets = []
          self._create_children(8)
  
  
      def _create_children(self, count: int):
          for i in range(count):
              # Create a panel
              new_child = QWidget()
              new_child.setFixedSize(64, 64)
              new_child.setParent(self)
              new_child.show()
  
              # Set the color
              pal = QPalette()
              pal.setColor(QPalette.Background, QColor(random.randint(100, 255), random.randint(100, 255), random.randint(100, 255)))
              new_child.setAutoFillBackground(True)
              new_child.setPalette(pal)
  
              self._child_widgets.append(new_child)
  
          self._move_panels()
  
      def _move_panels(self):
          num_per_row = max(int((self.width()) / 64), 1)
  
          for i in range(8):
              y = int(i / num_per_row)
              x = i % num_per_row
              self._child_widgets[i].move(x * 64, y * 64)
  
          num_rows = math.ceil(8 / float(num_per_row))
          min_height = num_rows * 64
          self.setFixedHeight(min_height)
  
      def resizeEvent(self, QResizeEvent):
          self._move_panels()
  
  
  if __name__ == '__main__':
      import callback_fix
      app = QApplication(sys.argv)
      gui = ChangingHeightWidget()
      gui.show()
      app.exec_()
  </code></pre>
  
  <p>Is there a way to stop this locking up happening? Alternatively, is there a way to achieve this effect without needing to call setFixedHeight inside the resizeEvent?</p>