qml加载ttf字体库

1,下载获取ttf文件

iconfont-阿里巴巴矢量图标库

字体图标下载 - FontAwesome 字体图标中文Icon

2,添加到项目文件

qml加载ttf字体库_第1张图片

3,项目添加字体库

#include 
#include 
#include 
#include 

int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
    QGuiApplication app(argc, argv);
    QQmlApplicationEngine engine;
    if(QFontDatabase::addApplicationFont(QLatin1String(":/iconfont.ttf"))==-1)
    {
        qDebug()<<"load font failed";
    }
//查询字体库名称
    QFontDatabase qfd;
    QStringList qsl = qfd.families();
    qDebug()<

4,Mac查看字体库 Unicode编码

4,qml调用

Text {
                    font.family : "iconfont"
                    font.pointSize:  20
                    text: "\ue889"
                    anchors.centerIn: parent
                    color: "white"
                }

你可能感兴趣的:(QT,qml,ttf)