Add QFontComboBox::setDisplayFont
Allows changing the font used to display a font family [ChangeLog][QtWidgets][QFontComboBox] Added the setDisplayFont() function, in order to be able to control the font used to render the font name and sample text (when previewing the fonts). Change-Id: I94bfef43142c5346237e3069449bd19dbacb7420 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
parent
63c0a1bd23
commit
98c2260c3b
@ -187,6 +187,7 @@ public:
|
||||
QFont currentFont;
|
||||
QHash<QFontDatabase::WritingSystem, QString> sampleTextForWritingSystem;
|
||||
QHash<QString, QString> sampleTextForFontFamily;
|
||||
QHash<QString, QFont> displayFontForFontFamily;
|
||||
|
||||
void _q_updateModel();
|
||||
void _q_currentChanged(const QString &);
|
||||
@ -238,6 +239,8 @@ void QFontFamilyDelegate::paint(QPainter *painter,
|
||||
if (hasLatin)
|
||||
font = font2;
|
||||
|
||||
font = comboPrivate->displayFontForFontFamily.value(text, font);
|
||||
|
||||
QRect r = option.rect;
|
||||
|
||||
if (option.state & QStyle::State_Selected) {
|
||||
@ -617,6 +620,28 @@ QString QFontComboBox::sampleTextForFont(const QString &fontFamily) const
|
||||
return d->sampleTextForFontFamily.value(fontFamily);
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the \a font to be used to display a given \a fontFamily (when the combo is open).
|
||||
|
||||
\since 6.3
|
||||
*/
|
||||
void QFontComboBox::setDisplayFont(const QString &fontFamily, const QFont &font)
|
||||
{
|
||||
Q_D(QFontComboBox);
|
||||
d->displayFontForFontFamily[fontFamily] = font;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the font (if set) to be used to display a given \a fontFamily (when the combo is open).
|
||||
|
||||
\since 6.3
|
||||
*/
|
||||
std::optional<QFont> QFontComboBox::displayFont(const QString &fontFamily) const
|
||||
{
|
||||
Q_D(const QFontComboBox);
|
||||
return d->displayFontForFontFamily.value(fontFamily, {});
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#include "qfontcombobox.moc"
|
||||
|
@ -86,6 +86,9 @@ public:
|
||||
void setSampleTextForFont(const QString &fontFamily, const QString &sampleText);
|
||||
QString sampleTextForFont(const QString &fontFamily) const;
|
||||
|
||||
void setDisplayFont(const QString &fontFamily, const QFont &font);
|
||||
std::optional<QFont> displayFont(const QString &fontFamily) const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void setCurrentFont(const QFont &f);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user