title: Qt: How to disable the "shrink-to-fit" for a QGridLayout?
body: <p>I'm using Qt5 on Windows7.<br>
  In my current app I try to display and remove a number of push-buttons.   </p>
  
  <pre><code>widget = new ButtonWidget(ui-&gt;frame); // frame is a QScrollArea
  connect(ui-&gt;addBtns,    SIGNAL(clicked()), widget, SLOT(addButtons()));
  connect(ui-&gt;deleteBtns, SIGNAL(clicked()), widget, SLOT(deleteButtons()));
  </code></pre>
  
  <p>And the <code>ButtonWidget</code> class is here:</p>
  
  <pre><code>ButtonWidget::ButtonWidget(QWidget * parent) : QWidget(parent)
  {
     gridLayout = new QGridLayout(parent);
  }
  
  static QStringList texts{...}; // various content (see explanations below)
  
  void ButtonWidget::addButtons()
  {
      for(auto i = 0; i &lt; texts.size(); i++)
      {
          gridLayout-&gt;addWidget(new QPushButton(texts[i], this), i / 5, i % 5);
      }
  }
  
  void ButtonWidget::deleteButtons()
  {
      while(gridLayout-&gt;count())
      {
          delete gridLayout-&gt;itemAt(0)-&gt;widget();
      }
  }
  </code></pre>
  
  <p>If I set <code>QStringList texts{"1\nok"};</code> I get this:<br>
  <a href="https://i.stack.imgur.com/FNBAN.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FNBAN.jpg" alt="enter image description here"></a><br>
  ...which is ugly (centered and expanded horizontally on all layout).   </p>
  
  <p>If I set <code>QStringList texts{"1\nok",...,"24\nok"};</code> I get this:<br>
  <a href="https://i.stack.imgur.com/QbaaB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QbaaB.jpg" alt="enter image description here"></a><br>
  ...which is/seems quite ok.   </p>
  
  <p>And finally, if I set <code>QStringList texts{"1\nok",...,"36\nok"};</code> I get this:<br>
  <a href="https://i.stack.imgur.com/jQ7J9.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jQ7J9.jpg" alt="enter image description here"></a><br>
  ...which is very bad, garbled, etc.   </p>
  
  <p>So, the question: Is there any way to fix this, i.e. to disable somehow this "shrink-to-fit" on the layout? A default button size would be just fine.<br>
  I would like to take advantage of the vertical-scroll feature of the QScrollArea, not to stuff and cram all the buttons in the (limited) available space... </p>