I gave it a quick try and it seems to work at least for a top level widget:
Qt Code:
  1. #include <QtGui>
  2.  
  3. class Window : public QWidget
  4. {
  5. Q_OBJECT
  6. public:
  7. Window()
  8. {
  9. int spacing = 20;
  10.  
  11. QSpinBox* spinbox = new QSpinBox(this);
  12. spinbox->setStyleSheet("background: red");
  13. spinbox->setValue(spacing);
  14.  
  15. QLabel* label = new QLabel(this);
  16. label->setStyleSheet("background: blue");
  17. label->setNum(spacing);
  18.  
  19. QVBoxLayout* layout = new QVBoxLayout(this);
  20. spacer = new QSpacerItem(spacing, spacing);
  21. layout->addWidget(spinbox);
  22. layout->addItem(spacer);
  23. layout->addWidget(label);
  24.  
  25. connect(spinbox, SIGNAL(valueChanged(int)), label, SLOT(setNum(int)));
  26. connect(spinbox, SIGNAL(valueChanged(int)), this, SLOT(setSpacing(int)));
  27. }
  28.  
  29. private slots:
  30. void setSpacing(int spacing)
  31. {
  32. spacer->changeSize(spacing, spacing);
  33. layout()->invalidate();
  34. }
  35.  
  36. private:
  37. QSpacerItem* spacer;
  38. };
  39.  
  40. int main(int argc, char* argv[])
  41. {
  42. QApplication a(argc, argv);
  43. Window w;
  44. w.show();
  45. return a.exec();
  46. }
  47.  
  48. #include "main.moc"
To copy to clipboard, switch view to plain text mode 
I suppose the spacing is not homogeneous over the layout? Otherwise you could simply use QBoxLayout::setSpacing().