title: How to display a scrollable list with a substantial amount of widgets as items in a Qt C++ app?
body: <p><strong>Goal:</strong> To have a scrollable list of custom widgets amounting hunderts of thousands (and possibly more) in a Qt5 C++ application under Windows 7, 10.</p>
  
  <p><strong>Problem:</strong> 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 <em>QLabels</em> (aprox 2k per <em>QLabel</em>).</p>
  
  <p><a href="https://stackoverflow.com/questions/21159095/qt-widget-for-displaying-large-amount-of-data-rows">Here</a> are some suggested solutions to a similar problem, which I don't find suitable for my case.</p>
  
  <p><strong>Example:</strong> The following example illustrates the problem. For the sake of the demonstration a list of <em>QLabels</em> is used, but it could be any class derived from <em>QWidget</em>.</p>
  
  <p><strong>MainWindow.h</strong></p>
  
  <pre><code>#ifndef MAINWINDOW_H
  #define MAINWINDOW_H
  
  #include &lt;QMainWindow&gt;
  #include &lt;QScrollArea&gt;
  #include &lt;QVBoxLayout&gt;
  #include &lt;QLabel&gt;
  
  class MainWindow : public QMainWindow
  {
      Q_OBJECT
  public:
      explicit MainWindow(QWidget *parent = 0);
  };
  
  #endif // MAINWINDOW_H
  </code></pre>
  
  <p><strong>MainWindow.cpp</strong></p>
  
  <pre><code>#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-&gt;setWidget(frame);
      scrollArea-&gt;setWidgetResizable(true);
  
      for (int n = 0; n &lt; N; n++) { l-&gt;addWidget(new QLabel(QString::number(n), this)); }
  
      resize(640, 480);
      setCentralWidget(scrollArea);
  }
  </code></pre>