diff options
author | J-P Nurmi <jpnurmi@digia.com> | 2013-08-06 14:08:47 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-08-15 11:37:27 +0200 |
commit | bff78163f6dc83d833b2097a51453523cfa7b00b (patch) | |
tree | 78907fb8dbb1c04d8f2e62861681315b482883e1 /src | |
parent | bab29dd76c7b6794e683220c918dca7c3f5a89fd (diff) |
QHeaderView::paintSection(): fix visible index handling
Sections may be hidden => QStyleOptionHeader::position must reflect the
state seen on the screen. Otherwise styles will give wrong visual
results.
Task-number: QTBUG-32203
Change-Id: I7ef86496be092bf6f52ec45f757b501f38c3a431
Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/widgets/itemviews/qheaderview.cpp | 24 | ||||
-rw-r--r-- | src/widgets/itemviews/qheaderview_p.h | 2 |
2 files changed, 23 insertions, 3 deletions
diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index edfbc5c8f1..864a55d2ea 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -2635,11 +2635,13 @@ void QHeaderView::paintSection(QPainter *painter, const QRect &rect, int logical // the section position int visual = visualIndex(logicalIndex); Q_ASSERT(visual != -1); - if (count() == 1) + bool first = d->isFirstVisibleSection(visual); + bool last = d->isLastVisibleSection(visual); + if (first && last) opt.position = QStyleOptionHeader::OnlyOneSection; - else if (visual == 0) + else if (first) opt.position = QStyleOptionHeader::Beginning; - else if (visual == count() - 1) + else if (last) opt.position = QStyleOptionHeader::End; else opt.position = QStyleOptionHeader::Middle; @@ -3062,6 +3064,22 @@ bool QHeaderViewPrivate::isSectionSelected(int section) const return s; } +bool QHeaderViewPrivate::isFirstVisibleSection(int section) const +{ + if (sectionStartposRecalc) + recalcSectionStartPos(); + const SectionItem &item = sectionItems.at(section); + return item.size > 0 && item.calculated_startpos == 0; +} + +bool QHeaderViewPrivate::isLastVisibleSection(int section) const +{ + if (sectionStartposRecalc) + recalcSectionStartPos(); + const SectionItem &item = sectionItems.at(section); + return item.size > 0 && item.calculatedEndPos() == length; +} + /*! \internal Returns the last visible (ie. not hidden) visual index diff --git a/src/widgets/itemviews/qheaderview_p.h b/src/widgets/itemviews/qheaderview_p.h index 7fda0c8873..f886430ba8 100644 --- a/src/widgets/itemviews/qheaderview_p.h +++ b/src/widgets/itemviews/qheaderview_p.h @@ -114,6 +114,8 @@ public: void _q_layoutChanged(); bool isSectionSelected(int section) const; + bool isFirstVisibleSection(int section) const; + bool isLastVisibleSection(int section) const; inline bool rowIntersectsSelection(int row) const { return (selectionModel ? selectionModel->rowIntersectsSelection(row, root) : false); |