summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Faure <david.faure@kdab.com>2018-03-08 22:31:33 +0100
committerDavid Faure <david.faure@kdab.com>2018-03-09 18:43:29 +0000
commit4c0a363a9a0b73c68fd252cba705396d4378b209 (patch)
tree997ef2f7a3dd1f16f67f5927bdbcaa482a988478 /src
parent5934f209c06bf622b6dc321de9a4a7b3dd6b0dda (diff)
QHeaderView: fix inconsistent saved state, ignored during restore
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 <tmartsum@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/itemviews/qheaderview.cpp6
1 files changed, 5 insertions, 1 deletions
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) {