Goal: To have a scrollable list of custom widgets amounting hunderts of thousands (and possibly more) in a Qt5 C++ application under Windows 7, 10.
Problem: The program stops responding after minimizing the window to the task bar and restoring it again. It doesn't crash though. The CPU usage constants 25%. The GUI doesn't become responsive again even after several minutes of waiting. Furthermore, a large amount of memory is being consumed in general (more than 200M), which I think is too much even for 100k QLabels (aprox 2k per QLabel).
Here are some suggested solutions to a similar problem, which I don't find suitable for my case.
Example: The following example illustrates the problem. For the sake of the demonstration a list of QLabels is used, but it could be any class derived from QWidget.
MainWindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QScrollArea>
#include <QVBoxLayout>
#include <QLabel>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
};
#endif // MAINWINDOW_H
MainWindow.cpp
#include "MainWindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
QScrollArea *scrollArea = new QScrollArea(this);
QFrame *frame = new QFrame();
QVBoxLayout *l = new QVBoxLayout(frame);
int N = 121004;
scrollArea->setWidget(frame);
scrollArea->setWidgetResizable(true);
for (int n = 0; n < N; n++) { l->addWidget(new QLabel(QString::number(n), this)); }
resize(640, 480);
setCentralWidget(scrollArea);
}