I have a nice widget that basically looks like a dialog box with a bunch of QSliders on it. The number of sliders varies depending on the situation when the dialog (not an actual QDialog; just a QWidget) is invoked.

Since the varying number of sliders causes the box to be different sizes at different times, I now want to clean things up a bit by confining the sliders to a QScrollArea. If I understand things correctly, such a scroll area would display however many sliders fit within its height, and one could scroll down to see the rest if there were more.

Anyway, I tried a (somewhat complicated) procedure like this:

In constructor of custom QWidget class (m_variableName = member variable):

Qt Code:
  1. CustomScrollBox::CustomScrollBox(QWidget* _parent){
  2.  
  3. setWindowTitle(...)
  4. ...
  5.  
  6. m_scrollArea = new QScrollArea(this);
  7. m_scrollAreaBox = new QGroupBox(m_scrollArea);
  8. m_layout = new QGridLayout();
  9. m_scrollAreaBox->setLayout(m_layout);
  10. m_scrollArea->setWidget(m_scrollAreaBox);
  11. m_scrollArea->setFixedHeight(250);
  12.  
  13. m_bottomButton = new QPushButton(this); //probably irrelevant
  14. ...
  15. [connect calls, etc.]
  16. }
To copy to clipboard, switch view to plain text mode 

After the constructor, the real, situation-dependent set-up of sliders occurs:

Qt Code:
  1. void
  2. CustomScrollBox::SetUpWidgets(){
  3.  
  4. for([however many sliders the situation calls for]){
  5. CustomSlider* s = new CustomSlider(this, label); //just a QWidget consisting of a QSlider and a QLabel to
  6. //the left of it
  7. ...
  8. m_layout->addWidget(s, [grid dimensions as needed]);
  9. }
  10.  
  11. ...
  12. [set text on bottom button, etc., and add it as well]
  13. }
To copy to clipboard, switch view to plain text mode 

This process causes nothing to show up on the overall dialog, except for an immobile scroll bar on the left. What, if possible, is the proper order of initialization steps to make this work? My guess is that I might have given something the wrong parent or set a layout at the wrong time, but the rearrganements I've tried so far haven't worked...