简体   繁体   English

只有一些 Font Awesome 5 图标可以在 Qt Qml 中使用

[英]Only some Font Awesome 5 icons work in Qt Qml

I am trying to show Font Aweseom 5 (5.10.2) icons in a Qt Qml label:我正在尝试在 Qt Qml 标签中显示 Font Aweseom 5 (5.10.2) 图标:

Label {
    text: "\uf2bb" + " x " + "\uf002"
    font.family: "Font Awesome 5 Free"
    //font.weight: Font.Normal
}

On Windows all icons work as expected.在 Windows 上,所有图标都按预期工作。 But on all other platforms (macOS, Android, iOS) only some icons (for instance \ ) are shown while others ( \ ) do not work and a simple rectangle is shown instead.但在所有其他平台(macOS、Android、iOS)上,仅显示一些图标(例如\ )而其他( \ )不起作用,而是显示一个简单的矩形。 But all icons work on all platforms when QWidgets are used.但是当使用 QWidgets 时,所有图标都适用于所有平台。

I verified that the "Font Awesome 5 Free" font is installed in the QFontDatabase using this utility list view:我使用此实用程序列表视图验证了 QFontDatabase 中安装了“Font Awesome 5 Free”字体:

ListView {
    anchors.fill: parent;
    model: Qt.fontFamilies()

    delegate: Item {
        height: 40;
        width: ListView.view.width
        Label {
            anchors.centerIn: parent
            text: modelData;
        }
    }
}

Has anyone an idea why some icons work in Qml, while others don't?有谁知道为什么有些图标可以在 Qml 中工作,而有些则不能?

Regards,问候,

Either setting the font weight to Font.Black or the font's style name to "Solid" fixes the problem:将字体粗细设置为Font.Black或将字体的样式名称设置为"Solid"解决问题:

Label {
    text: "\uf2bb" + " x " + "\uf002"
    font.family: "Font Awesome 5 Free"
    font.weight: Font.Black // this does the trick
}

Label {
    text: "\uf2bb" + " x " + "\uf002"
    font.family: "Font Awesome 5 Free"
    font.styleName: "Solid" // this does the trick
}

I fixed this problem with https://fontforge.org/我用https://fontforge.org/解决了这个问题

On file fa-solid-900.ttf I modified the field WWS Family (under tab TTF Names) from Font Awesome 5 Free to Font Awesome 5 Free Solid在文件fa-solid-900.ttf 中,我将字段WWS Family (在选项卡 TTF Names 下)从Font Awesome 5 FreeFont Awesome 5 Free Solid

Maybe Qt for Android uses this field and without modification the value is the same for fa-regular-400.ttf and fa-solid-900.ttf也许 Qt for Android 使用这个字段并且没有修改, fa-regular-400.ttffa-solid-900.ttf的值是相同的

Hope it helps希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM