title: How to add a Scroll Bar to a Grid Layout in Qt?
body: <p>I have a <code>QGridLayout</code> which will contain a bunch of widgets. The problem arose when the loop added too many widgets and they couldn't all fit on the page. I want to add a scroll bar but it doesn't display correctly.</p>
  
  <p>This function returns a tab which is added to the main layout, it contains the grid layout:</p>
  
  <pre><code>QTabWidget *RegistersTab::createTab()
  {
      QTabWidget *tab = new QTabWidget(this);
  
      std::vector&lt;QGridLayout*&gt; loVec; //to add to master layout
  
      for(int i=0; i&lt;2; i++) //number of pages
      {
          QWidget *client = new QWidget(this); //this part breaks it
          QScrollArea *scrollArea = new QScrollArea(this);
          scrollArea-&gt;setWidget(client);
  
          QTabWidget *tabPage = new QTabWidget(client);
  
          QGridLayout *loGrid = new QGridLayout(client);
          tabPage-&gt;setLayout(loGrid);
  
          QString title = QString("Page %1").arg(i);
          tab-&gt;addTab(tabPage, title);
  
          loVec.push_back(loGrid);
      }
      m_loGridVec.push_back(loVec);
  
      return tab;
  }
  </code></pre>
  
  <p>The <code>GridLayout</code> vector is there so I can add widgets and manipulate it later. At the moment I just get a grey box over the top of my tabs - so something is broken. If I remove the scroll area and set <code>(client)</code> to <code>(this)</code>.</p>
  
  <p>I'm guessing there's a simple correction to be made?</p>
  
  <p><strong>EDIT (how tab is made):</strong></p>
  
  <pre><code>ui-&gt;lo-&gt;addWidget(m_tab);
  
  m_tab-&gt;addTab(createTab(), title); // m_tabCbc is a QTabWidget;
  </code></pre>