Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
chehrlic committed Feb 22, 2018
1 parent ef20989 commit 2551e96
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/widgets/itemviews/qheaderview.cpp
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
Expand Up @@ -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);
Expand All @@ -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)));
Expand Down

0 comments on commit 2551e96

Please sign in to comment.