After some experimentation, I think I got it to work using layouts:
[image: fc07db6c-0a5c-45dd-93fe-a2a3d7483b96.png]
All I did was create QVBoxLayout and put scrollareawidgetcontents in the layout. The rest is the same except that I no longer need to set widget geometry since it is being placed in a layout.
command_local->scrollAreaWidgetContents = new QWidget(); // create scroll area contents widget for the qscrollarea
command_local->scrollAreaWidgetContents->setObjectName(QString::fromUtf8("scrollAreaWidgetContents"));
command_local->commands_layout = new QVBoxLayout(command_local->scrollAreaWidgetContents);
for(int i=0; i < command_local->command_list_s.count(); i ++){
command_local->command_list_s[i].Command_checkbox = new QCheckBox(command_local->command_list_s[i].name, command_local->scrollAreaWidgetContents);
command_local->commands_layout->addWidget(command_local->command_list_s[i].Command_checkbox);
}
command_local->start_test_button = new QPushButton(command_local->scrollAreaWidgetContents);
command_local->start_test_button->setObjectName(QString::fromUtf8("start_test_button"));
command_local->start_test_button->setText(QCoreApplication::translate("Widget", "Start test", nullptr));
command_local->commands_layout->addWidget(command_local->start_test_button);
connect(command_local->start_test_button, &QPushButton::clicked, this, &MainWindow::Start_test);
command_local->test_status = new QLineEdit(command_local->scrollAreaWidgetContents);
command_local->test_status->setObjectName(QString::fromUtf8("test_status"));
command_local->test_status->setText(QCoreApplication::translate("Widget", "IDLE", nullptr));
command_local->commands_layout->addWidget(command_local->test_status);
command_local->cmd_selected_test = new QLineEdit(command_local->scrollAreaWidgetContents);
command_local->cmd_selected_test->setObjectName(QString::fromUtf8("selected_test"));
command_local->cmd_selected_test->setText(QCoreApplication::translate("Widget",action->text().toStdString().c_str(), nullptr));
command_local->commands_layout->addWidget(command_local->cmd_selected_test);
ui->Testing_scroll_area->setWidget(command_local->scrollAreaWidgetContents);