From b53f997d8f20938d46b755eca54b4ec9a40e4ffe Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 20 Oct 2018 21:23:04 +0200 Subject: [PATCH] QHeaderView: check for changed roles in dataChanged() QHeaderView::dataChanged() did not check for the modified roles which lead to unneeded size calculations even if the size did not change. Avoid it by only looking at the relevant roles (DisplayRole, DecorationRole, SizeHintRole and FontRole). [ChangeLog][QtWidgets][QHeaderView] dataChanged now respects the given roles to avoid useless recomputations Fixes: QTBUG-71172 Change-Id: I0de53897347a72bddc425ae1fae8f2560ad0e977 Reviewed-by: David Faure --- src/widgets/itemviews/qheaderview.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index e9091ca1a2..62abf56751 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -3117,9 +3117,25 @@ void QHeaderView::scrollContentsBy(int dx, int dy) \reimp \internal */ -void QHeaderView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &) +void QHeaderView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles) { Q_D(QHeaderView); + if (!roles.isEmpty()) { + const auto doesRoleAffectSize = [](int role) -> bool { + switch (role) { + case Qt::DisplayRole: + case Qt::DecorationRole: + case Qt::SizeHintRole: + case Qt::FontRole: + return true; + default: + // who knows what a subclass or custom style might do + return role >= Qt::UserRole; + } + }; + if (std::none_of(roles.begin(), roles.end(), doesRoleAffectSize)) + return; + } d->invalidateCachedSizeHint(); if (d->hasAutoResizeSections()) { bool resizeRequired = d->globalResizeMode == ResizeToContents;