summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@digia.com>2014-05-23 23:49:38 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-05-26 11:03:15 +0200
commitf7af9fb63244b114653c157d3eef3e6c64f3196a (patch)
treeac20f6d0b57f6d82ff2557ebc6e571012526ad0f
parent92c6bfa0b238614db328bdc7a57cd0390adc95a5 (diff)
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 <Friedemann.Kleint@digia.com>
-rw-r--r--src/widgets/itemviews/qheaderview.cpp12
-rw-r--r--src/widgets/styles/qcommonstyle.cpp7
-rw-r--r--src/widgets/styles/qwindowsvistastyle.cpp13
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<QIcon>(variant);
if (opt.icon.isNull())
opt.icon = qvariant_cast<QPixmap>(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<QStyleOptionHeader *>(const_cast<QStyleOption *>(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;
}