From f7af9fb63244b114653c157d3eef3e6c64f3196a Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Fri, 23 May 2014 23:49:38 +0200 Subject: [PATCH] Account for the sort indicator being placed above the text on Vista In WindowsVista style and later the sort indicator is placed above the text as opposed to alongside it. Therefore the extra space given is moved to the common style allowing styles that have it placed differently to easily ensure it is not included. Task-number: QTBUG-19915 Change-Id: Ic21fcc1d95f4c3cc2eb9c465e1c8afb9b805389a Reviewed-by: Friedemann Kleint --- src/widgets/itemviews/qheaderview.cpp | 12 +++--------- src/widgets/styles/qcommonstyle.cpp | 7 +++++++ src/widgets/styles/qwindowsvistastyle.cpp | 13 +++++++++++++ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index f1bdfc8709..eac25d3833 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -2762,15 +2762,9 @@ QSize QHeaderView::sectionSizeFromContents(int logicalIndex) const opt.icon = qvariant_cast(variant); if (opt.icon.isNull()) opt.icon = qvariant_cast(variant); - QSize size = style()->sizeFromContents(QStyle::CT_HeaderSection, &opt, QSize(), this); - if (isSortIndicatorShown()) { - int margin = style()->pixelMetric(QStyle::PM_HeaderMargin, &opt, this); - if (d->orientation == Qt::Horizontal) - size.rwidth() += size.height() + margin; - else - size.rheight() += size.width() + margin; - } - return size; + if (isSortIndicatorShown()) + opt.sortIndicator = QStyleOptionHeader::SortDown; + return style()->sizeFromContents(QStyle::CT_HeaderSection, &opt, QSize(), this); } /*! diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index f1cf46169a..d7030c5d72 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -4783,6 +4783,13 @@ QSize QCommonStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, sz.setHeight(margin + qMax(iconSize, txt.height()) + margin); sz.setWidth((nullIcon ? 0 : margin) + iconSize + (hdr->text.isNull() ? 0 : margin) + txt.width() + margin); + if (hdr->sortIndicator != QStyleOptionHeader::None) { + int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, hdr, widget); + if (hdr->orientation == Qt::Horizontal) + sz.rwidth() += sz.height() + margin; + else + sz.rheight() += sz.width() + margin; + } } break; case CT_TabWidget: diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp index 9c3e1eac99..bc78ea3296 100644 --- a/src/widgets/styles/qwindowsvistastyle.cpp +++ b/src/widgets/styles/qwindowsvistastyle.cpp @@ -1970,6 +1970,19 @@ QSize QWindowsVistaStyle::sizeFromContents(ContentsType type, const QStyleOption sz -= QSize(2*border, 2*border); } return sz; + case CT_HeaderSection: + { + // When there is a sort indicator it adds to the width but it is shown + // above the text natively and not on the side + if (QStyleOptionHeader *hdr = qstyleoption_cast(const_cast(option))) { + QStyleOptionHeader::SortIndicator sortInd = hdr->sortIndicator; + hdr->sortIndicator = QStyleOptionHeader::None; + sz = QWindowsXPStyle::sizeFromContents(type, hdr, size, widget); + hdr->sortIndicator = sortInd; + return sz; + } + break; + } default: break; }