要使此代码正常工作,您只需注释掉常规的FontLoader。我设置了正确的font.family,但是它没有任何改变。与什么问题可以联系?
要测试代码,您可以下载字体here。
更新。正如@folibis所建议的,原因是FontLoader名称的冲突:它们都为“ Font Awesome 5 Free”。手动设置FontLoader.name不提供任何内容,只是不能用新名称引用。有任何解决方法的想法吗?
import QtQuick 2.10
import QtQuick.Window 2.10
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
// Comment out this to make everything working
FontLoader {
id: regular
source: "qrc:/Font Awesome 5 Free-Regular-400.otf"
}
FontLoader {
id: solid
source: "qrc:/Font Awesome 5 Free-Solid-900.otf"
}
Text {
anchors.centerIn: parent
text: "Icon: \uf5ca"
font {
family: solid.name
pointSize: 30
}
}
}
答案 0 :(得分:1)
The two .otf files have indeed the same name: "Font Awesome 5 Free".
When a Text uses this family, the text is displayed with the regular version.
When a Text uses this family and defines font.bold: true
(or font.weight: Font.Bold
), the text is displayed with the solid version.
The following code shows these different uses:
import QtQuick 2.10
import QtQuick.Window 2.10
Window {
visible: true
width: 1280
height: 720
title: qsTr("Hello World")
FontLoader {
source: "qrc:/Font Awesome 5 Free-Regular-400.otf"
}
FontLoader {
source: "qrc:/Font Awesome 5 Free-Solid-900.otf"
}
Column {
anchors.centerIn: parent
spacing: 60
Text {
text: "Icon: \uf5ca" + " - The - " + font.family
font {
family: "Font Awesome 5 Free"
pointSize: 30
}
}
Text {
text: "Icon: \uf5ca" + " - The - " + font.family
font {
family: "Font Awesome 5 Free"
pointSize: 30
bold: true
}
}
}
}
答案 1 :(得分:0)
在Qt 5.9+中,为了使用完整版本的FontAwesome 5 Free
,您需要将styleName
属性设置为Solid
:
Text {
font {
family: awesomeFontSolid.name; pointSize: 48;
styleName: "Solid" //<---
}
text: "\uf142"
}