From 0e2dae902b316a40a1d861198da55118d2155964 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Mon, 18 Jun 2018 21:38:58 +0200 Subject: QTreeView: speedup expanding items via keyPressEvent/asterisk Expanding items with asterisk is done with expand(QModelIndex) which in the end calls layout() which is very slow and useless until all items are expanded. Therefore delay the relayouting until all items are expanded. [ChangeLog][QtWidgets][QTreeView] Speedup expanding items when pressing asterisk Task-number: QTBUG-39486 Change-Id: Ieb798fc22e9fa0dcac4bb92de7e3ed3ebb9d1c38 Reviewed-by: David Faure --- src/widgets/itemviews/qtreeview.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index 9a3c05ee38..b339fe0f3b 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -1991,19 +1991,21 @@ void QTreeView::keyPressEvent(QKeyEvent *event) if (d->isIndexValid(current) && d->model && d->itemsExpandable) { switch (event->key()) { case Qt::Key_Asterisk: { + // do layouting only once after expanding is done + d->doDelayedItemsLayout(); QStack parents; parents.push(current); - while (!parents.isEmpty()) { - QModelIndex parent = parents.pop(); - for (int row = 0; row < d->model->rowCount(parent); ++row) { - QModelIndex child = d->model->index(row, 0, parent); - if (!d->isIndexValid(child)) - break; - parents.push(child); - expand(child); - } + while (!parents.isEmpty()) { + QModelIndex parent = parents.pop(); + for (int row = 0; row < d->model->rowCount(parent); ++row) { + QModelIndex child = d->model->index(row, 0, parent); + if (!d->isIndexValid(child)) + break; + parents.push(child); + expand(child); } - expand(current); + } + expand(current); break; } case Qt::Key_Plus: expand(current); -- cgit v1.2.3