summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2012-09-28 09:49:05 (GMT)
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-01 07:12:53 (GMT)
commit4679c6901fc7c388fdf6c022d3499708222ef1f1 (patch)
tree032c5f4a70b49e3f5e60ddffb6534f357231af85
parent3f10b20e56c0f5a3768becf8a9e21b5d00a66bc1 (diff)
downloadQt-4679c6901fc7c388fdf6c022d3499708222ef1f1.zip
Qt-4679c6901fc7c388fdf6c022d3499708222ef1f1.tar.gz
Qt-4679c6901fc7c388fdf6c022d3499708222ef1f1.tar.bz2
Fix issue with mispositioned family name i QFontComboBox
Mac OS X 10.7 comes with the family of Stix fonts, some of which exposed an ugly layout bug in the QFontComboBox because the ascent/descent ratio is very large due to a very high ascent, so centering the text vertically might cause most of the text to be clipped away. The solution is to detect when the ascent is larger than the height of the destination rectangle (hence a large part of the characters will be clipped) and use the actual bounding rect for centralizing instead. Since this only happens for a very few of the fonts, the overhead of getting the bounding rect should be tolerable. Task-number: QTBUG-26691 Change-Id: I4f1a9b3c63138fde4dfdfa99d8581458c59b7ff6 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
-rw-r--r--src/gui/widgets/qfontcombobox.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/gui/widgets/qfontcombobox.cpp b/src/gui/widgets/qfontcombobox.cpp
index b0a0828..18510bc 100644
--- a/src/gui/widgets/qfontcombobox.cpp
+++ b/src/gui/widgets/qfontcombobox.cpp
@@ -164,7 +164,18 @@ void QFontFamilyDelegate::paint(QPainter *painter,
QFont old = painter->font();
painter->setFont(font);
- painter->drawText(r, Qt::AlignVCenter|Qt::AlignLeading|Qt::TextSingleLine, text);
+
+ // If the ascent of the font is larger than the height of the rect,
+ // we will clip the text, so it's better to align the tight bounding rect in this case
+ // This is specifically for fonts where the ascent is very large compared to
+ // the descent, like certain of the Stix family.
+ QFontMetricsF fontMetrics(font);
+ if (fontMetrics.ascent() > r.height()) {
+ QRectF tbr = fontMetrics.tightBoundingRect(text);
+ painter->drawText(r.x(), r.y() + (r.height() + tbr.height()) / 2.0, text);
+ } else {
+ painter->drawText(r, Qt::AlignVCenter|Qt::AlignLeading|Qt::TextSingleLine, text);
+ }
if (writingSystem != QFontDatabase::Any)
system = writingSystem;