From c0e45ae851c96dfebdebfd1e85b7b7eee6540bd1 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Thu, 15 Feb 2018 20:24:40 +0100 Subject: [PATCH] QHeaderView: properly restore hidden section size on layoutChanged() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/widgets/itemviews/qheaderview.cpp | 10 +++++++--- .../widgets/itemviews/qheaderview/tst_qheaderview.cpp | 5 +++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index c90a61d4ff1..edef2e9bf82 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -2168,15 +2168,19 @@ void QHeaderViewPrivate::_q_sectionsAboutToBeChanged() 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 3594e7fa018..c69c0de9499 100644 --- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp @@ -2286,7 +2286,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); @@ -2298,6 +2300,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)));