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. This is a port of 4679c6901fc7c388fdf6c022d3499708222ef1f1 from Qt 4.8. Task-number: QTBUG-26691 Change-Id: Ia2014775e5baf0568df3290f2dc4ad64fb5a74bd Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
This commit is contained in:
parent
3d620088b4
commit
84100c9085
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user