do not assume the resolved fonts have the same point size in QFontFamilyDelegate

that means no fancy drawing of the font family name with the font itself,
fonts however may not even have the glyphs for that (symbol fonts?)

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-03-31 07:50:01 +03:00
parent b18f9e246e
commit 5a9a707716

View file

@ -66,10 +66,6 @@ void QFontFamilyDelegate::paint(QPainter *painter,
const QModelIndex &index) const
{
QString text = index.data(Qt::DisplayRole).toString();
QFont font(option.font);
QFont systemfont = fdb.font(font.family(), font.styleName(), font.pointSize());
font.setPointSize(systemfont.pointSize() * 3 / 2);
font.setFamily(text);
QRect r = option.rect;
@ -93,13 +89,8 @@ void QFontFamilyDelegate::paint(QPainter *painter,
else
r.setLeft(r.left() + actualSize.width() + 4);
QFont old = painter->font();
painter->setFont(font);
painter->drawText(r, Qt::AlignVCenter|Qt::AlignLeft|Qt::TextSingleLine, text);
painter->setFont(old);
if (option.state & QStyle::State_Selected)
painter->restore();
@ -110,11 +101,8 @@ QSize QFontFamilyDelegate::sizeHint(const QStyleOptionViewItem &option,
{
QString text = index.data(Qt::DisplayRole).toString();
QFont font(option.font);
// font.setFamily(text);
QFont systemfont = fdb.font(font.family(), font.styleName(), font.pointSize());
font.setPointSize(systemfont.pointSize() * 3/2);
QFontMetrics fontMetrics(font);
return QSize(fontMetrics.width(text), fontMetrics.height());
return fontMetrics.size(Qt::TextSingleLine, text);
}