1、在main.qml中使用FontLoader加载目标字库
FontLoader {
id: cnFont
source:"qrc:/fonts/stsong.ttf"
}
此方法需要将字库添加到qrc资源中一起打包,最终程序体积太大
2、添加中文字体库到系统中,目标目录为/usr/share/fonts/kbm-fonts,其中kbm-fonts是我自定的目录名,存放我需要的字库文件。如此qt库会自动定位到此处字库中的中文
3、查看当前系统中所用字库的代码
#include <QFontDatabase>
QFont font;
QFontDatabase database;
foreach (const QString &family, database.families()) {
qDebug()<<family;
}
qDebug()<<"\r\n show chinese font. \r\n"
foreach(const QString &family, database.families(QFontDatabase::SimplifiedChinese)) {
qDebug() << family;
}
font.setPointSize(15);
font.setFamily("stsong");
app.setFont(font);