summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-02-15 20:24:40 +0100
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-02-22 18:17:41 +0000
commit2551e96d782f5381460cc144235f22ac8ef9e7ef (patch)
treeeb56584bae64fc050a099bda6b525024f6113071
parentef20989bf05c13b18eba4aac6f464c5be71136fa (diff)
QHeaderView: properly restore hidden section size on layoutChanged()
During (re)storing the sections within layoutChanged handling, the hidden section size was not properly stored which lead to a section size of 0 when the section was unhided afterwards. Task-number: QTBUG-66413 Task-number: QTBUG-65478 Change-Id: I0b714c7e0530a1eae82b3bb0e0dc80ed576522d0 Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com> (cherry picked from commit c0e45ae851c96dfebdebfd1e85b7b7eee6540bd1)
-rw-r--r--src/widgets/itemviews/qheaderview.cpp10
-rw-r--r--tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp5
2 files changed, 12 insertions, 3 deletions
diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp
index e1aec3f4bd..5edf7e0547 100644
--- a/src/widgets/itemviews/qheaderview.cpp
+++ b/src/widgets/itemviews/qheaderview.cpp
@@ -2080,15 +2080,19 @@ void QHeaderViewPrivate::_q_layoutAboutToBeChanged()
sectionItems[visual].size = lastSectionSize;
}
for (int i = 0; i < sectionItems.size(); ++i) {
- const auto &s = sectionItems.at(i);
+ auto s = sectionItems.at(i);
// only add if the section is not default and not visually moved
if (s.size == defaultSectionSize && !s.isHidden && s.resizeMode == globalResizeMode)
continue;
+ const int logical = logicalIndex(i);
+ if (s.isHidden)
+ s.size = hiddenSectionSize.value(logical);
+
// ### note that we are using column or row 0
layoutChangePersistentSections.append({orientation == Qt::Horizontal
- ? model->index(0, logicalIndex(i), root)
- : model->index(logicalIndex(i), 0, root),
+ ? model->index(0, logical, root)
+ : model->index(logical, 0, root),
s});
if (layoutChangePersistentSections.size() > 1000)
diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
index 6dae2cf8e4..d0d4fd52b3 100644
--- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
+++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
@@ -2275,7 +2275,9 @@ void tst_QHeaderView::QTBUG7833_sectionClicked()
tv.setModel(proxyModel);
const int section4Size = tv.horizontalHeader()->sectionSize(4) + 1;
+ const int section5Size = section4Size + 1;
tv.horizontalHeader()->resizeSection(4, section4Size);
+ tv.horizontalHeader()->resizeSection(5, section5Size);
tv.setColumnHidden(5, true);
tv.setColumnHidden(6, true);
tv.horizontalHeader()->swapSections(8, 10);
@@ -2287,6 +2289,9 @@ void tst_QHeaderView::QTBUG7833_sectionClicked()
QCOMPARE(tv.horizontalHeader()->logicalIndex(8), 10);
QCOMPARE(tv.horizontalHeader()->logicalIndex(10), 8);
QCOMPARE(tv.horizontalHeader()->sectionSize(4), section4Size);
+ tv.setColumnHidden(5, false); // unhide, section size must be properly restored
+ QCOMPARE(tv.horizontalHeader()->sectionSize(5), section5Size);
+ tv.setColumnHidden(5, true);
QSignalSpy clickedSpy(tv.horizontalHeader(), SIGNAL(sectionClicked(int)));
QSignalSpy pressedSpy(tv.horizontalHeader(), SIGNAL(sectionPressed(int)));