So, I was right and fixed it by adding QScrollArea with QGridLayout. I created the test example:
Code:
QPushButton *testButton1 = new QPushButton("Test1");
testButton1->setMinimumHeight(23);
QPushButton *testButton2 = new QPushButton("Test2");
testButton2->setMinimumHeight(23);
QPushButton *testButton3 = new QPushButton("Test");
testButton3->setMinimumHeight(23);
QPushButton *testButton4 = new QPushButton("Test");
testButton4->setMinimumHeight(23);
QPushButton *testButton5 = new QPushButton("Test");
testButton5->setMinimumHeight(23);
QPushButton *testButton6 = new QPushButton("Test");
testButton6->setMinimumHeight(23);
QPushButton *testButton7 = new QPushButton("Test");
testButton7->setMinimumHeight(23);
QPushButton *testButton8 = new QPushButton("Test");
testButton8->setMinimumHeight(23);
QPushButton *testButton9 = new QPushButton("Test");
testButton9->setMinimumHeight(23);
QPushButton *testButton10 = new QPushButton("Test");
testButton10->setMinimumHeight(23);
QPushButton *testButton11 = new QPushButton("Test");
testButton11->setMinimumHeight(23);
QPushButton *testButton12 = new QPushButton("Test");
testButton12->setMinimumHeight(23);
QPushButton *testButton13 = new QPushButton("Test");
testButton13->setMinimumHeight(23);
QPushButton *testButton14 = new QPushButton("Test");
testButton14->setMinimumHeight(23);
QPushButton *testButton15 = new QPushButton("Test");
testButton15->setMinimumHeight(23);
QPushButton *testButton16 = new QPushButton("Test");
testButton16->setMinimumHeight(23);
QFont sectionFont;
sectionFont.setBold(true);
QLabel *section1Label = new QLabel("Section 1", this);
section1Label->setFont(sectionFont);
QLabel *section2Label = new QLabel("Section 2", this);
section2Label->setFont(sectionFont);
QWidget *testWidget = new QWidget(this);
QScrollArea *testScrollArea = new QScrollArea(this);
testScrollArea->setWidgetResizable(true);
testScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
testScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
QGridLayout *testGridLayout = new QGridLayout();
testGridLayout->addWidget(testButton1, 1, 0);
testGridLayout->addWidget(testButton2, 1, 1);
testGridLayout->addWidget(testButton3, 1, 2);
testGridLayout->addWidget(testButton4, 1, 3);
testGridLayout->addWidget(testButton5, 1, 4);
testGridLayout->addWidget(section1Label, 2, 0);
testGridLayout->addWidget(testButton6, 3, 0);
testGridLayout->addWidget(testButton7, 3, 1);
testGridLayout->addWidget(testButton8, 3, 2);
testGridLayout->addWidget(testButton9, 3, 3);
testGridLayout->addWidget(testButton10, 3, 4);
testGridLayout->addWidget(section2Label, 4, 0);
testGridLayout->addWidget(testButton11, 5, 0);
testGridLayout->addWidget(testButton12, 5, 1);
testGridLayout->addWidget(testButton13, 5, 2);
testGridLayout->addWidget(testButton14, 5, 3);
testGridLayout->addWidget(testButton15, 5, 4);
testGridLayout->addWidget(testButton16, 5, 0);
testWidget->setLayout(testGridLayout);
testScrollArea->setWidget(testWidget);
QHBoxLayout *mainHBoxLayout = new QHBoxLayout();
mainHBoxLayout->addWidget(testScrollArea);
setLayout(mainHBoxLayout);
Now it adds the scrollbars and the space between those buttons:
[image: bc395c8d-a4ce-4abf-a2fc-d15307f07f25.png]
The issue is resolved.