Hi,
I'm trying to build a scrollable list of data lines with several data fields each, and a headline describing those data fields.
Of course, I don't want the headline to be scrolled out of focus when scrolling down. However, since the lines hold quite a few items, I want the headline to be included in any horizontal scrolling event and synchronized with the actual data fields, to make the most use of the horizontally available space.
Something like this:
Item name -- Data field 1 -- Data field 2 -- Data field 3 -- ...
Item1 Value11 Value12 Value13 ...
Item2 Value21 Value22 Value23 ...
Item3 Value31 Value32 Value33 ...
...
To do this, I have tried nesting two QScrollAreas. But I always get the problem that with two nested QScrollAreas the total size of the area is fixed and doesn't make use of more space available (see screenshot), while a single QScrollArea always does.
The test code is a bit improvised and combines a scroll area in Designer with another one that is directly coded.
I had the same problem when all elements were hand-coded.
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
for (int l = 0; l < 15; l++)
{
labeltext = "Label ";
label
[l
] = new QLabel(labeltext
);
codedSALayout->addWidget(label[l]);
}
codedSAWidget->setLayout(codedSALayout);
codedScrollArea->setWidget(codedSAWidget);
uiSALayout->addWidget(codedScrollArea);
ui->scrollAreaWidget->setLayout(uiSALayout);
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
codedScrollArea = new QScrollArea;
codedSAWidget = new QWidget;
codedSALayout = new QHBoxLayout;
uiSALayout= new QHBoxLayout;
label = new QLabel*[15];
QString labeltext;
for (int l = 0; l < 15; l++)
{
labeltext = "Label ";
labeltext += QString::number(l);
label[l] = new QLabel(labeltext);
codedSALayout->addWidget(label[l]);
}
codedSAWidget->setLayout(codedSALayout);
codedScrollArea->setWidget(codedSAWidget);
uiSALayout->addWidget(codedScrollArea);
ui->scrollAreaWidget->setLayout(uiSALayout);
}
To copy to clipboard, switch view to plain text mode
Can anyone give me a hint how to make two nested QScrollAreas use the available space, or how to otherwise implement such a list with a headline ?
Thank you !
Bookmarks