本文仅简单记录如何使用 Qt 加载外部字体文件,并遍历字体名称和样式名称。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| bool LoadFont(const QString& fontPath) { const int fontId = QFontDatabase::addApplicationFont(fontPath); if (fontId == -1) { return false; }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) const QStringList fontFamilyList = fontDb.applicationFontFamilies(fontId);
QString fontFamily; foreach (fontFamily, fontFamilyList) { qDebug() << "Family:" << fontFamily;
const QStringList fontStyleList = QFontDatabase::styles(fontFamily); QString fontStyle; foreach (fontStyle, fontStyleList) { qDebug() << "\tStyle:" << fontStyle; } } #else QFontDatabase fontDb; const QStringList fontFamilyList = fontDb.applicationFontFamilies(fontId);
QString fontFamily; foreach (fontFamily, fontFamilyList) { qDebug() << "Family:" << fontFamily;
const QStringList fontStyleList = fontDb.styles(fontFamily); QString fontStyle; foreach (fontStyle, fontStyleList) { qDebug() << "\tStyle:" << fontStyle; } } #endif
return true; }
|
限于政策原因,在您看到该文章时,博客可能已经关闭了评论功能🥺
您可以通过在 blog-comment 项目中提交Issue来间接地发表评论🍀