diff options
author | Alexander Volkov <a.volkov@rusbitech.ru> | 2014-11-12 17:13:22 +0300 |
---|---|---|
committer | Alexander Volkov <a.volkov@rusbitech.ru> | 2014-12-11 10:26:41 +0100 |
commit | 53022e04bb578c12cdc9460d7ce4eedefbc8c2e4 (patch) | |
tree | 8c70e70662ee3cb7e7922bb121f42119d570b195 /src/widgets/itemviews/qheaderview.cpp | |
parent | 6386bafb40f9d172f80d20cac824b7018e0a37a4 (diff) |
Make the defaultSectionSize property of QHeaderView style dependent
Add new enum items PM_HeaderDefaultSectionSizeHorizontal and
PM_HeaderDefaultSectionSizeVertical to QStyle and get corresponding
values in QHeaderView. This way we get rid of some magic constants in
QHeaderView and we can have reasonable values for the default section
size for high-DPI displays.
[ChangeLog][QtWidgets][QHeaderView] Default section size is now style-dependent by default.
[ChangeLog][QtWidgets][QHeaderView] Added resetDefaultSectionSize().
Change-Id: I44e152c5cf0bec1e5d78e1e62f47a2d1f761dfbf
Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
Diffstat (limited to 'src/widgets/itemviews/qheaderview.cpp')
-rw-r--r-- | src/widgets/itemviews/qheaderview.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index f1ebc4505e..e887434d14 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -1515,6 +1515,11 @@ void QHeaderView::setCascadingSectionResizes(bool enable) This property only affects sections that have \l Interactive or \l Fixed as their resize mode. + By default, the value of this property is style dependent. + Thus, when the style changes, this property updates from it. + Calling setDefaultSectionSize() stops the updates, calling + resetDefaultSectionSize() will restore default behavior. + \sa setSectionResizeMode(), minimumSectionSize */ int QHeaderView::defaultSectionSize() const @@ -1531,6 +1536,15 @@ void QHeaderView::setDefaultSectionSize(int size) d->setDefaultSectionSize(size); } +void QHeaderView::resetDefaultSectionSize() +{ + Q_D(QHeaderView); + if (d->customDefaultSectionSize) { + d->updateDefaultSectionSizeFromStyle(); + d->customDefaultSectionSize = false; + } +} + /*! \since 4.2 \property QHeaderView::minimumSectionSize @@ -2209,6 +2223,10 @@ bool QHeaderView::event(QEvent *e) resizeSections(); } break; } + case QEvent::StyleChange: + if (!d->customDefaultSectionSize) + d->updateDefaultSectionSizeFromStyle(); + break; default: break; } @@ -3465,6 +3483,7 @@ void QHeaderViewPrivate::setDefaultSectionSize(int size) executePostedLayout(); invalidateCachedSizeHint(); defaultSectionSize = size; + customDefaultSectionSize = true; if (state == QHeaderViewPrivate::ResizeSection) preventCursorChangeInSetOffset = true; for (int i = 0; i < sectionItems.count(); ++i) { @@ -3485,6 +3504,17 @@ void QHeaderViewPrivate::setDefaultSectionSize(int size) viewport->update(); } +void QHeaderViewPrivate::updateDefaultSectionSizeFromStyle() +{ + Q_Q(QHeaderView); + if (orientation == Qt::Horizontal) { + defaultSectionSize = q->style()->pixelMetric(QStyle::PM_HeaderDefaultSectionSizeHorizontal, 0, q); + } else { + defaultSectionSize = qMax(q->minimumSectionSize(), + q->style()->pixelMetric(QStyle::PM_HeaderDefaultSectionSizeVertical, 0, q)); + } +} + void QHeaderViewPrivate::recalcSectionStartPos() const // linear (but fast) { int pixelpos = 0; @@ -3632,6 +3662,7 @@ void QHeaderViewPrivate::write(QDataStream &out) const out << sectionItems; out << resizeContentsPrecision; + out << customDefaultSectionSize; } bool QHeaderViewPrivate::read(QDataStream &in) @@ -3708,6 +3739,14 @@ bool QHeaderViewPrivate::read(QDataStream &in) if (in.status() == QDataStream::Ok) // we haven't read past end resizeContentsPrecision = tmpint; + bool tmpbool; + in >> tmpbool; + if (in.status() == QDataStream::Ok) { // we haven't read past end + customDefaultSectionSize = tmpbool; + if (!customDefaultSectionSize) + updateDefaultSectionSizeFromStyle(); + } + return true; } |