gpt4 book ai didi

qt - QML 不使用细字体粗细

转载 作者:行者123 更新时间:2023-12-04 12:42:31 26 4
gpt4 key购买 nike

我有一个使用免费 Encode Sans font 的 QML 应用程序,它有 9 个权重匹配 Qt 5.6's font weights .

我已将所有 .ttf 添加到我的项目中,并使用 FontLoader 加载它们。一切都完美无缺,除了字体的粗细。

除了下面的代码之外,我还尝试在 FontLoader 上为 Thin 提供一个唯一的 id,以确保家族名称相同(确实如此)。如何调试此问题并使 Thin 正常工作?

Screenshot of all weights being used. The Thin weight is listed first, and shows the same result as the Normal weight. All other weights vary as expected and look correct.

### 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
}
}

如果重要的话,在 Ubuntu 上使用 Qt 5.6。

最佳答案

这是一个 Qt 错误:[QTBUG-53196] Thin fonts do not work in Qt

您可以使用的一种解决方法是使用 styleName property相反,它是在 Qt 5.6 中引入的。这种方法的缺点是,如果您的文本中有一些嵌入的粗体(使用 html 或富文本),它将不起作用(如果我理解这个 bug 正确的话)。

你可以这样使用它:

### 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
}
}

关于qt - QML 不使用细字体粗细,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37573143/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com