Skip to content

Commit

Permalink
QHeaderView: Fix crash in layout about to change
Browse files Browse the repository at this point in the history
Before there was a risk looking up e.g index -1 if there
were no visible sections in layoutAboutToChange.

Change-Id: Ic911e4292e8e8c4892fef1c0f34cf7dccaad2bac
Task-number: QTBUG-65478
Reviewed-by: David Faure <david.faure@kdab.com>
(cherry picked from commit e8425f9e52c9df0ce0fbf122adff3ef6930f9961)
  • Loading branch information
tmartsum committed Mar 2, 2018
1 parent a038f77 commit 133196e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/widgets/itemviews/qheaderview.cpp
Expand Up @@ -2075,9 +2075,11 @@ void QHeaderViewPrivate::_q_layoutAboutToBeChanged()
layoutChangePersistentSections.clear();
layoutChangePersistentSections.reserve(std::min(10, sectionItems.count()));
// after layoutChanged another section can be last stretched section
if (stretchLastSection) {
if (stretchLastSection && lastSectionLogicalIdx >= 0 && lastSectionLogicalIdx < sectionItems.count()) {
const int visual = visualIndex(lastSectionLogicalIdx);
sectionItems[visual].size = lastSectionSize;
if (visual >= 0 && visual < sectionItems.size()) {
sectionItems[visual].size = lastSectionSize;
}
}
for (int i = 0; i < sectionItems.size(); ++i) {
auto s = sectionItems.at(i);
Expand Down
Expand Up @@ -2352,6 +2352,7 @@ void tst_QHeaderView::checkLayoutChangeEmptyModel()
QtTestModel tm;
tm.cols = 11;
QTableView tv;
tv.verticalHeader()->setStretchLastSection(true);
tv.setModel(&tm);

const int section4Size = tv.horizontalHeader()->sectionSize(4) + 1;
Expand Down

0 comments on commit 133196e

Please sign in to comment.