QML不使用Thin字体重量 [英] QML not using Thin font weight
问题描述
我有一个QML应用程序,使用免费的
$ b
# ## main.qml
FontLoader {source:qrc:/fonts/encodesans/EncodeSans-Thin.ttf}
FontLoader {source:qrc:/fonts/encodesans/EncodeSans-ExtraLight.ttf }
FontLoader {source:qrc:/fonts/encodesans/EncodeSans-Light.ttf}
FontLoader {id:mainFont; source:qrc:/fonts/encodesans/EncodeSans-Regular.ttf}
FontLoader {source:qrc:/fonts/encodesans/EncodeSans-Medium.ttf}
FontLoader {source:qrc :/fonts/encodesans/EncodeSans-SemiBold.ttf}
FontLoader {source:qrc:/fonts/encodesans/EncodeSans-Bold.ttf}
FontLoader {source:qrc:/ fonts / encodesans / EncodeSans-ExtraBold.ttf}
FontLoader {source:qrc:/fonts/encodesans/EncodeSans-Black.ttf}
列{
TextLine {weight: Thin}
TextLine {weight:ExtraLight}
TextLine {weight:Light}
TextLine {weight:Normal}
TextLine {weight: }
TextLine {weight:DemiBold}
TextLine {weight:Bold}
TextLine {weight:ExtraBold}
TextLine {weight:Black}
$ / code>
### TextLine.qml
导入QtQuick 2.0
文本{
属性字符串权重
text:1 2 3 4 font.weight:Font。+ weight
color:white
font {
weight:Font [weight]
family:mainFont.name
pixelSize:36
$ b $ / code $ / pre
$ b 在Ubuntu上使用Qt 5.6 ,如果它很重要的话。
这是一个Qt错误: [QTBUG-53196]细字体在Qt中不起作用
您可以使用的一种解决方法是使用 你可以像这样使用它: I have a QML app using the freely-available Encode Sans font, which comes in 9 weights that match Qt 5.6's font weights. I have added all .ttf to my project, and am using a In addition to the code below I have tried providing a unique
Using Qt 5.6 on Ubuntu, if it matters. This is a Qt bug : [QTBUG-53196] Thin fonts do not work in Qt One workaround you could use is using the You can use it like this :
这篇关于QML不使用Thin字体重量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! styleName
属性,而是在Qt 5.6中引入的。
这种方法的缺点是,如果你的文本中有一些嵌入的粗体(使用html或者富文本),它将不起作用(如果我明白这个
### TextLine.qml
导入QtQuick 2.0
文本{
属性字符串重量
text:1 2 3 4 font.weight:Font。+ weight
color:white
font {
styleName:weight
family:mainFont.name
pixelSize:36
}
}
FontLoader
to load them. Everything works perfectly, except for the Thin weight of the font.id
on the FontLoader for Thin, to ensure that the family name is the same (it is). How can I debug this problem and get Thin working?### main.qml
FontLoader { source:"qrc:/fonts/encodesans/EncodeSans-Thin.ttf" }
FontLoader { source:"qrc:/fonts/encodesans/EncodeSans-ExtraLight.ttf" }
FontLoader { source:"qrc:/fonts/encodesans/EncodeSans-Light.ttf" }
FontLoader { id:mainFont; source:"qrc:/fonts/encodesans/EncodeSans-Regular.ttf" }
FontLoader { source:"qrc:/fonts/encodesans/EncodeSans-Medium.ttf" }
FontLoader { source:"qrc:/fonts/encodesans/EncodeSans-SemiBold.ttf" }
FontLoader { source:"qrc:/fonts/encodesans/EncodeSans-Bold.ttf" }
FontLoader { source:"qrc:/fonts/encodesans/EncodeSans-ExtraBold.ttf" }
FontLoader { source:"qrc:/fonts/encodesans/EncodeSans-Black.ttf" }
Column {
TextLine { weight:"Thin" }
TextLine { weight:"ExtraLight" }
TextLine { weight:"Light" }
TextLine { weight:"Normal" }
TextLine { weight:"Medium" }
TextLine { weight:"DemiBold" }
TextLine { weight:"Bold" }
TextLine { weight:"ExtraBold" }
TextLine { weight:"Black" }
}
### TextLine.qml
import QtQuick 2.0
Text {
property string weight
text: "1 2 3 4 font.weight: Font."+weight
color:"white"
font {
weight: Font[weight]
family: mainFont.name
pixelSize: 36
}
}
styleName
property instead wich was introduced in Qt 5.6 .
The disadvantage of this method is that if you have some embedded bold in your text (with html or rich text), it won't work (if I understand this bug correctly).### TextLine.qml
import QtQuick 2.0
Text {
property string weight
text: "1 2 3 4 font.weight: Font."+weight
color:"white"
font {
styleName: weight
family: mainFont.name
pixelSize: 36
}
}