summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Bache-Wiig <jens.bache-wiig@digia.com>2012-11-02 13:28:57 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-11-02 15:24:20 +0100
commit7d497846f0a44e796b347c5c7bb355237d1a409d (patch)
treee8b604112480041b3fb35355ead1b8075e90bf36
parent0a91c9df01ec8f0c4aef9ce6e5e9bc3804fb80c2 (diff)
Fix font and positioning of headerview labels on mac
The old code rendered text too large. On desktop components, the widget workaround ensured that text was clipped. This should address both problems. Since we anyway do not adapt the height to font size, I dont se a point in supporting custom fonts here. Change-Id: If3c0509cdff4dbadfd98bd4b1934eaa665148cbf Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
-rw-r--r--src/widgets/styles/qmacstyle_mac.mm24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm
index 83895b64b0..04fdb99b93 100644
--- a/src/widgets/styles/qmacstyle_mac.mm
+++ b/src/widgets/styles/qmacstyle_mac.mm
@@ -3451,6 +3451,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
break;
case CE_HeaderLabel:
if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
+ p->save();
QRect textr = header->rect;
if (!header->icon.isNull()) {
QIcon::Mode mode = QIcon::Disabled;
@@ -3464,8 +3465,10 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
textr.translate(pixmap.width() + 2, 0);
}
+ p->setFont(qt_app_fonts_hash()->value("QSmallFont", QFont()));
proxy()->drawItemText(p, textr, header->textAlignment | Qt::AlignVCenter, header->palette,
header->state & State_Enabled, header->text, QPalette::ButtonText);
+ p->restore();
}
break;
case CE_ToolButtonLabel:
@@ -4558,17 +4561,22 @@ QRect QMacStyle::subElementRect(SubElement sr, const QStyleOption *opt,
rect = qt_qrectForHIRect(contentRect);
}
break;
- case SE_HeaderLabel:
- if (qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
- rect = QCommonStyle::subElementRect(sr, opt, widget);
- if (widget && widget->height() <= 22){
- // We need to allow the text a bit more space when the header is
- // small, otherwise it gets clipped:
- rect.setY(0);
- rect.setHeight(widget->height());
+ case SE_HeaderLabel: {
+ int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt, widget);
+ rect.setRect(opt->rect.x() + margin, opt->rect.y(),
+ opt->rect.width() - margin * 2, opt->rect.height() - 2);
+ if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
+ // Subtract width needed for arrow, if there is one
+ if (header->sortIndicator != QStyleOptionHeader::None) {
+ if (opt->state & State_Horizontal)
+ rect.setWidth(rect.width() - (opt->rect.height() / 2) - (margin * 2));
+ else
+ rect.setHeight(rect.height() - (opt->rect.width() / 2) - (margin * 2));
}
}
+ rect = visualRect(opt->direction, opt->rect, rect);
break;
+ }
case SE_ProgressBarGroove:
case SE_ProgressBarLabel:
break;