From 4679c6901fc7c388fdf6c022d3499708222ef1f1 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Fri, 28 Sep 2012 11:49:05 +0200 Subject: 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 --- src/gui/widgets/qfontcombobox.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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; -- cgit v0.12