summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQiang Li <liqianga@uniontech.com>2021-03-03 19:26:27 +0800
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-03-08 14:39:10 +0000
commit13cb272a705359beee0b28dccd544485b49c9eff (patch)
treee85de5c11775210a6e932c39ac71bb5812a08aeb /src
parent667d0eb3c5e57f9a6d8838910ece8c46b398781f (diff)
Fix the crashes when animated QTreeWidgetItems are hidden
QTreeView's drawTree implementation performs lazy layouting when calling itemDecorationAt. If animations are enabled, this can change the list of items, and invalidate the copy made earlier. Don't copy the list of items, use a reference instead so that code iterating over the items later operates on valid data. Add an assert in the private itemHeight method, it must not be called with an index that is out of bounds. Fixes: QTBUG-42469 Change-Id: Ifdb782881447912e00baffd1c407de10a1d8d0d4 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit f140ef04a0c54c2c8a699db33433b8d7235d137c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/itemviews/qtreeview.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp
index c0b0ee4f2d..49585d8b26 100644
--- a/src/widgets/itemviews/qtreeview.cpp
+++ b/src/widgets/itemviews/qtreeview.cpp
@@ -1486,7 +1486,8 @@ void QTreeViewPrivate::adjustViewOptionsForIndex(QStyleOptionViewItem *option, c
void QTreeView::drawTree(QPainter *painter, const QRegion &region) const
{
Q_D(const QTreeView);
- const QList<QTreeViewItem> viewItems = d->viewItems;
+ // d->viewItems changes when posted layouts are executed in itemDecorationAt, so don't copy
+ const QList<QTreeViewItem> &viewItems = d->viewItems;
QStyleOptionViewItem option;
initViewItemOption(&option);
@@ -3484,6 +3485,7 @@ int QTreeViewPrivate::indentationForItem(int item) const
int QTreeViewPrivate::itemHeight(int item) const
{
+ Q_ASSERT(item < viewItems.count());
if (uniformRowHeights)
return defaultItemHeight;
if (viewItems.isEmpty())