From 4c0a363a9a0b73c68fd252cba705396d4378b209 Mon Sep 17 00:00:00 2001 From: David Faure Date: Thu, 8 Mar 2018 22:31:33 +0100 Subject: QHeaderView: fix inconsistent saved state, ignored during restore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This happens because QTreeView disconnects QHeaderView's _q_layoutChanged slot (!). So the stretching of the last section, done in _q_layoutAboutToBeChanged, invalidated total length, but didn't recalculate it (since that's done in _q_layoutChanged). As a result, length was inconsistent, and saveState would save that, and restoreState() would early-return, not doing anything. Let's just ensure length is always consistent, so we don't depend on the complex issue of whether _q_layoutChanged should be called or not. This an adapted backport of 4a04eea4f4 from 5.11, the unittest shows that c0e45ae851 is missing in this branch though. Change-Id: I4137a19e0a6fdf820dd53fb55e858d1d04a2c113 Reviewed-by: Thorbjørn Lund Martsum --- src/widgets/itemviews/qheaderview.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index 27da7a16e5..d5ab9f3208 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -2078,7 +2078,11 @@ void QHeaderViewPrivate::_q_layoutAboutToBeChanged() if (stretchLastSection && lastSectionLogicalIdx >= 0 && lastSectionLogicalIdx < sectionItems.count()) { const int visual = visualIndex(lastSectionLogicalIdx); if (visual >= 0 && visual < sectionItems.size()) { - sectionItems[visual].size = lastSectionSize; + auto &itemRef = sectionItems[visual]; + if (itemRef.size != lastSectionSize) { + length += lastSectionSize - itemRef.size; + itemRef.size = lastSectionSize; + } } } for (int i = 0; i < sectionItems.size(); ++i) { -- cgit v1.2.3