Daniel
Daniel

Reputation: 325

QTableWidget performance optimization

I have a QTableWidget that can display a huge number of elements (like, 20000 elements). Displaying per se and scrolling up and down works find, however, populating the widget works extremely slowly. I found out that constructing the QVector of elements (strings) that are displayed works very fast, however, inserting the elements into the QTableWidget is very slow. I need to implement filtration over the elements, so if the user filters half of the elements out with a wildcard, it's still necessary to clean the QTreeWidget and insert 10000 elements back (or hide 10000 elements which is equally slow). Reasonably fast performance is critical here because the user can't wait for several minutes every time he presses a button. Valgrind doesn't help much as apparently much of the resources are eaten by some implicitly called functions, particularly QHeaderView::sectionSize() and QHeaderView::isSectionHidden()

Upvotes: 1

Views: 1122

Answers (1)

Arenim
Arenim

Reputation: 4237

Migrate Your code to model-view pattern.

  1. Create a model (subclass QStandardItemModel) and place all Your data there.
  2. Display all the data in QTableView, ensure everything is OK
  3. Now, You can use QSortFilterModel model for fast data-filtering, or you can subclass QProxyModel for more complex filters.

Upvotes: 5

Related Questions