ScrollArea to Flowlayout of QTableWidgets Part-2
Fixing issues related to Part-1
Table of contents
Introduction
This post is in continuation of ScrollArea to FlowLayout of QTableWidgets Part-1 In this post, you will learn how to fix the issue related to working of the scrollarea which occurs in Part-1.
Idea
This is the diagram of the required design. The green-colored boxes, in this figure, shows QTableWidgets.
Here's the tree diagram.
You can see a clear picture of the hierarchy diagram by clicking on this link.
Issue Fixing
If you compare this diagram with the one discussed in Part-1 of this post; the difference lies in applying scroll area and setting the central widget of the main window. In Part-1; scroll area was applied to mSWidget which is also selected as the central widget of the main window whereas in Part-2, scroll area is applied to flowWidget and it is also set as the central widget of the main window which in turn lets scroll area to be applied to the entire region of the main window.
Code
Window::Window
{
QMainWindow *a= new QMainWindow(this);
QScrollArea *scroll =new QScrollArea();
QWidget *flowWidget = new QWidget(this);
FlowLayout *flowL = new FlowLayout(this);
int n=20;
int dataLoggers=5;
flowWidget->setLayout(flowL);
flowWidget ->setMinimumSize(2000,2000);
QVector <QWidget *> dataTableWidgets(n);
QVector <QVBoxLayout *>dataTableLayouts(n);
QVector <QLabel *> departmentNames(n);
QVector <QTableWidget *> dataTables(n);
for (int kk=0;kk<n;kk++)
{
QWidget *dataTableWidgets= new QWidget(this);
QVBoxLayout *dataTableLayouts = new QVBoxLayout();
QLabel *departmentNames = new QLabel(QString("Department %1").arg(kk+1));
dataTableLayouts->addWidget(departmentNames);
QTableWidget *dataTables = new QTableWidget();
dataTableLayouts->addWidget(dataTables);
dataTables->setColumnCount(2);
dataTables->setRowCount(dataLoggers);
dataTableWidgets->setLayout(dataTableLayouts);
flowL->addWidget(dataTableWidgets);
dataTableWidgets->setMinimumSize(100,100);
}
scroll->setWidget(flowWidget);
flowWidget->setLayout(flowL);
//this ->show();
a->setCentralWidget(scroll);
a->show();
}
Output
Conclusion
Through the posts in Know Qt Series,I've tried to put my experience of exploring Qt. I've made many mistakes and learned to fix them by digging deeper into the concepts. The more one questions , more one can learn. I never restricted myself from questioning and was satisfied with what I could learn through this process but the process of learning and experimenting is still on.