title: QScrollArea not working as expected with QWidget and QVBoxLayout
body: <p>So I have this <code>QFrame</code> which is the parent widget (represented by <code>this</code> in the code). In this widget, I want to place a <code>QWidget</code> at 10 px from top (and 10 px from bottom, as a result of which it will have a height of 140px, whereas parent is 160px). The <code>QWidget</code> will have a number of custom buttons inside it in a vertical layout, in a scroll area, so that when the height of the buttons combined exceeds the <code>QWidget's</code> height (140px), scroll sets in automatically. Because the scroll is not for the entire parent widget, but only for a child widget, the scroll should apply only to the child widget here. Here is my code:</p>
  
  <pre><code>//this is a custom button class with predefined height and some formatting styles
  class MyButton: public QPushButton
  {
  
  public:
      MyButton(std::string aText, QWidget *aParent);
  
  };
  
  MyButton::MyButton(std::string aText, QWidget *aParent): QPushButton(QString::fromStdString(aText), aParent)
  {
      this-&gt;setFixedHeight(30);
      this-&gt;setCursor(Qt::PointingHandCursor);
      this-&gt;setCheckable(false);
      this-&gt;setStyleSheet("background: rgb(74,89,98);   color: black; border-radius: 0px; text-align: left; padding-left: 5px; border-bottom: 1px solid black;");
  }
  
  //this is where I position the parent widget first, and then add sub widget
  this-&gt;setGeometry(x,y,width,160);
  this-&gt;setStyleSheet("border-radius: 5px; background:red;");
  
  //this is the widget which is supposed to be scrollable
  QWidget *dd = new QWidget(this);
  dd-&gt;setGeometry(0,10,width,140);
  dd-&gt;setStyleSheet("background: blue;");
  
  QVBoxLayout *layout = new QVBoxLayout();
  dd-&gt;setLayout(layout);
  
  for (int i = 0; i &lt; fValues.size(); i++)
  {
      MyButton *button = new MyButton(fValues[i],dd);
      layout-&gt;addWidget(button);
  }
  
  QScrollArea *scroll = new QScrollArea(this);
  scroll-&gt;setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
  scroll-&gt;setWidget(dd);
  </code></pre>
  
  <p>Contrary to my expectations, this is what I am getting (attached image). What am I doing wrong, and how do I fix this?</p>
  
  <p><img src="https://i.stack.imgur.com/kQHlf.png" alt="enter image description here"></p>