diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index c90a61d4ff..edef2e9bf8 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 3594e7fa01..c69c0de949 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)));