title: How can i make widgets overflow to make a scrollbar appear in Qt?
body: <p>The structure of my widgets is :</p>
  
  <p><strong>QWidget customized to be a panel with rounded borders.</strong></p>
  
  <p>To contain an area with scrollbar inside the borders with a margin, then I put this inside:</p>
  
  <p><strong>QScrollArea with a QVBoxLayout  (vertically adding content)</strong></p>
  
  <p>Then I add inside of it a series of :</p>
  
  <p><strong>QGroupBox with title with spacing 0, and a QFormLayout</strong></p>
  
  <p>The formlayout doesn´t work as I thought it would. The widgets inside are the labels + spinboxes, all of them.</p>
  
  <p>Here's an image:</p>
  
  <p><img src="https://i.stack.imgur.com/q8MfA.png" alt="Image"></p>
  
  <p>First. They are not centered. I don´t know why.</p>
  
  <p>Second. They are all given the same fixed size, as I told them, but they are piled anyway, not squashed, so they hide each other. Why doesn´t it stay that size and the parent QScrollArea shows the scrollbar outside?. That´s what i want.</p>
  
  <p>I don´t want the contents to be squashed or stretched. I want them to be on the top. If the screen is very big, the panel will be long, but the contents will be on the top, allways with the same size.</p>
  
  <hr>
  
  <p>Somebody requested the code, so i copy it here, but the code it really big... I think it's more confusing. But well, ill remove the lines with no meaning. Here is the part you see in that box:</p>
  
  <pre><code>  // THE PANEL OUTSIDE (A QWIDGET) is mainParametersLayout_. This particular scroll bar inside
    // is cameraModeParametersPanel_
  
    cameraModeParametersPanel_ = new QScrollArea();
    cameraModeParametersPanel_-&gt;setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    cameraModeParametersPanel_-&gt;setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    mainParametersLayout_-&gt;addWidget( cameraModeParametersPanel_ );
  
    // HERE THERE ARE TWO MORE QGROUP BOXES. THE ONE THAT DOESN´T STAY THE WAY I SHOWED IS THIS. 
  
    QVBoxLayout* mainCameraLayout = new QVBoxLayout(cameraModeParametersPanel_);
    mainCameraLayout-&gt;setSpacing(5);
  
    // GROUP BOX 
    QGroupBox* activeCameraParametersGroup = new QGroupBox();
    activeCameraParametersGroup-&gt;setObjectName( parametersContainerName );
    activeCameraParametersGroup-&gt;setTitle(strings-&gt;cameraModeCameraParamsTitle);
    mainCameraLayout-&gt;addWidget( activeCameraParametersGroup );
  
    // LAYOUT
    QFormLayout* paramLayout = new QFormLayout( activeCameraParametersGroup );
    paramLayout-&gt;setRowWrapPolicy(QFormLayout::DontWrapRows);
    paramLayout-&gt;setFormAlignment( Qt::AlignHCenter | Qt::AlignTop );
    paramLayout-&gt;setLabelAlignment(Qt::AlignRight);
  
  
    // Iso : Spin Integer
    isoSpin = new SmartIntSpinButtons( control-&gt;getMinISO(), control-&gt;getMaxISO() );
    isoSpin-&gt;setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    paramLayout-&gt;addRow(strings-&gt;cameraISOCapString, isoSpin);
  
    // FStop: Spin Double
    fstopSpin = new SmartDoubleSpinButtons( control-&gt;getMinFStop(), control-&gt;getMaxFStop(), 2);
    fstopSpin-&gt;setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    paramLayout-&gt;addRow(strings-&gt;cameraFStopString, fstopSpin);
  
  
  
    // some other spins here...
  
  
  
    // Camera position: 3 Spin Double (X,Y,Z)
    camPosSpinX = new SmartDoubleSpinButtons( control-&gt;getMinCamPos(), control-&gt;getMaxCamPos(), 1);
    camPosSpinY = new SmartDoubleSpinButtons( control-&gt;getMinCamPos(), control-&gt;getMaxCamPos(), 1);
    camPosSpinZ = new SmartDoubleSpinButtons( control-&gt;getMinCamPos(), control-&gt;getMaxCamPos(), 1);
  
    camPosSpinX-&gt;setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    camPosSpinY-&gt;setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    camPosSpinZ-&gt;setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
  
    paramLayout-&gt;addRow( new QLabel( strings-&gt;cameraPositionString ) );
    QHBoxLayout* positionLy = new QHBoxLayout();
    positionLy-&gt;addWidget( camPosSpinX );
    positionLy-&gt;addWidget( camPosSpinY );
    positionLy-&gt;addWidget( camPosSpinZ );
    paramLayout-&gt;addRow( positionLy );
  
    // Target Position: 3 Spin Double( X,Y,Z )
    camTargetPosSpinX = new SmartDoubleSpinButtons( control-&gt;getMinCamTarget(), control-&gt;getMaxCamTarget(), 1);
    camTargetPosSpinY = new SmartDoubleSpinButtons( control-&gt;getMinCamTarget(), control-&gt;getMaxCamTarget(), 1);
    camTargetPosSpinZ = new SmartDoubleSpinButtons( control-&gt;getMinCamTarget(), control-&gt;getMaxCamTarget(), 1);
  
    camTargetPosSpinX-&gt;setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    camTargetPosSpinY-&gt;setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    camTargetPosSpinZ-&gt;setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
  
    paramLayout-&gt;addRow( new QLabel( strings-&gt;cameraTargetPositionString ));
    QHBoxLayout* targetLy = new QHBoxLayout();
    targetLy-&gt;addWidget( camTargetPosSpinX );
    targetLy-&gt;addWidget( camTargetPosSpinY );
    targetLy-&gt;addWidget( camTargetPosSpinZ );
    paramLayout-&gt;addRow( targetLy );
  
    // and the resoultion spins, which are the same style like the last one (but only X and Y).
  </code></pre>
  
  <p>Now comes the stylesheet of all:</p>
  
  <pre><code>/* THE PANEL THAT CONTAINS THE QSCROLLBAR OUTSIDE */
  
  SmartPanel
  {
      background-image: url(:/resources/images/containers/panel_bg.png);
      background-repeat: repeat-y;
      background-position: left top;
      background-color: white;
      border: 1px solid #aaa;
      border-radius: 10;
      min-width: 20px;
      padding: 5px;
  
  }
  
  
  QScrollArea#parametersPanelScrollArea
  {
      background: transparent;
      border: none;
  }
  
  
  /* the qgroupbox */  
  
  
  QGroupBox#parametersContainer
  {
    background-color: white;
    padding-top: 25px;
    border-style: solid;
    border-width: 1px;
    border-color: #aaa;
    border-radius: 10px;
  }
  
  QGroupBox#parametersContainer::title  {
      subcontrol-origin: margin;
      subcontrol-position: top center;
      border: 1px solid #aaa;
      margin-top: -5px;
      padding: 8px 5px 5px 5px;
      font-size: 18px;
      border-radius: 5px;
  }    
  
  
  /* ------------------ SPINBOX WIDGET ------------------------------------------*/
  
  QWidget#intSpin, QWidget#doubleSpin
  {
      min-height: 20px;
      border: 1px solid #ccc;
      padding: 0px;
      border-top-left-radius: 4px;
      border-bottom-left-radius: 4px;
      background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #ddd, stop:1 #fff);
  }
  
  QPushButton#upSpinBtn,
  QPushButton#downSpinBtn
  {
      border-radius: 0px;
      /*background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #ddd, stop:1 #fff);*/
      background-repeat: no-repeat;
      background-position: center;
      border: none;
  }
  
  QPushButton#upSpinBtn
  {   
      background-image: url(:/resources/images/buttons/up_sm_arrow.png);
  }
  
  QPushButton#downSpinBtn
  {
      background-image: url(:/resources/images/buttons/down_sm_arrow.png);
  }
  </code></pre>