proper use of FontLoader (unable to set font weight)
-
Hi all -
I'm trying to follow the example code in the page on FontLoader (Qt 6.4). My attempts to set the font weight aren't working. Here's a code snippet:
Window { FontLoader { id: rubik source: "qrc:/fonts/Rubik/Rubik-VariableFont_wght.ttf" } ColumnLayout { ToolBar { id: tool Component.onCompleted: console.log("tool font is " + tool.font) font.family: rubik.name font.pixelSize: 24 font.weight: Font.Bold Layout.fillWidth: true RowLayout { width: parent.width ToolButton { text: qsTr("red") } ToolButton { text: qsTr("green") } ToolButton { text: qsTr("blue") } } } } }
The font.pixelSize works, but the font.weight doesn't.
The console.log() returns this:
qml: tool font is QFont(Rubik Light,-1,24,5,700,0,0,0,0,0,0,0,0,0,0,1)
What might I be doing wrong here? I admit I'm a little confused about the distinction between the font.family and the name properties of FontLoader.
Thanks...
EDIT:
corrected the title of this post.
-
name : string
This property holds the name of the font family. It is set automatically when a font is loaded using the source property.
This is equivalent to the family property of the FontLoader's font property.
https://doc.qt.io/qt-6/qml-qtquick-fontloader.html#name-propfont.family == name properties of FontLoader
font.weight does not have anything to do with font loader. Try other choices to see if there are any changes.
-
name : string
This property holds the name of the font family. It is set automatically when a font is loaded using the source property.
This is equivalent to the family property of the FontLoader's font property.
https://doc.qt.io/qt-6/qml-qtquick-fontloader.html#name-propfont.family == name properties of FontLoader
font.weight does not have anything to do with font loader. Try other choices to see if there are any changes.
-
@JoeCFD I don't understand - when you say "Try other choices," what are you referring to?
-
@mzimmers Font weighting is classified on a scale from 0 to 99, where a weight of 0 is ultralight, and 99 is extremely black. The following values are supported:
https://doc.qt.io/qt-6/qml-font.html@JoeCFD I've tried several of those values, and none seem to change the appearance. All my other font settings seem to work (I tried a couple others just to experiment):
font.family: rubik.name font.pixelSize: 24 font.capitalization: Font.AllUppercase font.strikeout: true font.weight: Font.DemiBold
Just not weight.
-
Interesting, though I'm not sure I understand it all.
Using the full legacy names of the fonts may be a suitable work-around which should always work on Window
How do I determine the "full legacy name" of the font I'm trying to use? Or, is that even the right fix for this?
Thanks...
-
Interesting, though I'm not sure I understand it all.
Using the full legacy names of the fonts may be a suitable work-around which should always work on Window
How do I determine the "full legacy name" of the font I'm trying to use? Or, is that even the right fix for this?
Thanks...
-
@mzimmers https://wiki.archlinux.org/title/Microsoft_fonts#Legacy_packages
may be or may not be.