title: How to create a scrollable QVBoxLayout?
body: <p>I'm trying to put a <code>QVBoxLayout</code> inside a <code>QScrollArea</code> in order for it to be scrollable vertically. However items don't seem to be added to it.</p>
  
  <p>I saw a suggestion that I ought to create an inner widget that the ScrollArea uses and to place the layout inside that, although it doesn't seem to have worked. My structure is supposed to look like this:</p>
  
  <pre><code>+-------------------------------
  | QScrollArea(realmScroll)
  | +----------------------------
  | | QWidget(realmScrollInner)
  | | +-------------------------
  | | | QVBoxLayout(realmLayout)
  </code></pre>
  
  <p>And the code to do this:</p>
  
  <pre><code># Irrelevant, added for context (this works)
  centralWidget = QWidget(self)
  self.container = QVBoxLayout(centralWidget)
  centralWidget.setLayout(self.container)
  self.setCentralWidget(centralWidget)
  
  # Where trouble starts
  self.realmScroll = QScrollArea(self.container.widget())
  self.realmScroll.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
  
  self.realmLayout = QVBoxLayout(self.container.widget())
  
  self.realmScrollInner = QWidget(self.realmScroll)
  self.realmScrollInner.setLayout(self.realmLayout)
  
  self.realmScroll.setWidget(self.realmScrollInner)
  self.container.addWidget(self.realmScroll)
  
  # Doesn't add to realmLayout
  self.realmLayout.addWidget(QLabel("test"))
  </code></pre>
  
  <p>I'm still learning Qt (2 days in), so in-depth answers to where I'm going wrong would be appreciated.</p>
  
  <p><strong>Update</strong>:</p>
  
  <p>It seems that the <code>addWidget(QLabel())</code> works right up until the <code>realmScrollInner</code> has been set as <code>realmScroll</code>'s widget.  Since I'd like to add elements after the UI has been displayed  I have to do this, which I'm not sure is really correct:</p>
  
  <pre><code>self.realmLayout.addWidget(QLabel("test"))
  
  # realmScrollInner bound to realmScroll
  realmScroll.setWidget(realmScrollInner)
  self.container.addWidget(realmScroll)
  
  # Access realmScroll's widget and then layout to add
  realmScroll.widget().layout().addWidget(QLabel("test"))
  </code></pre>
  
  <p>But if you remove that first call to <code>addWidget</code> before the widget has been bound (so the layout has no widgets), then bind to the ScrollArea widgets added afterwards are not displayed. Perhaps the ScrollArea needs repainting (although I don't see a method for that)?</p>
  
  <p><strong>Update 2</strong>: Calling <code>repaint()</code> on realmScroll or its contained widget does nothing, as does calling <code>activate/update()</code> on the layout.</p>