I am trying to use a QScrollArea as a tab page, but for some reason I cannot get the child widgets to layout correctly using a QFormLayout.
I am not using Qt Designer in this case as i am dynamically adding rows to the form layout.

Here is the code. AbstractPropertyPage is the class that is added to the tab widget. For the purpose of this post, i have omitted all but the relevant code, but i have other subclasses of AbstractPropertyPage which add specific properties to the page.
Qt Code:
  1. class AbstractPropertyPage : public QScrollArea{
  3. protected:
  4. QScrollArea* scrollArea;
  5. QWidget* scrollAreaContents;
  6. QFormLayout* formLayout;
  8. public:
  9. AbstractPropertyPage(QWidget* parent = 0);
  11. void addRow(String labelText, QWidget* widget) {
  12. formLayout->addRow(labelText, widget);
  13. }
  14. //...
  15. };
  17. AbstractPropertyPage::AbstractPropertyPage(QWidget* parent) :
  18. QWidget(parent) {
  19. scrollAreaContents = new QWidget(this);
  20. formLayout = new QFormLayout(scrollAreaContents);
  21. formLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
  22. this->setWidget(scrollAreaContents);
  23. }
  25. //...
To copy to clipboard, switch view to plain text mode 

The subclasses then add rows:
Qt Code:
  1. somePropertyWidget = makeLineEdit();
  2. addRow(tr("Some Property"), somePropertyWidget);
To copy to clipboard, switch view to plain text mode 

These widgets are then added to the tab widget:
Qt Code:
  1. void PropertiesWindow::createPages() {
  2. //...
  3. tabWidget->addTab(new SomePropertyPage());
  4. //...
  5. }
To copy to clipboard, switch view to plain text mode 

I have also tried different approaches, such as subclassing QWidget instead of QScrollArea and add a QScrollArea to the widget. The widget would have a layout (e.g. vertical layout) such that the scroll area would fill the entire widget.

I tried it in Designer, laying it out how it should look. As i could not set a QScrollArea as the tab widget (it automatically put a QWidget in), i did the second approach. But the generated code looked identical to mine.

I don't know what i am doing wrong.