Beginner problems with QML and glyphs
-
Hi,
I'm new to QT. At the moment I'm playing around for testing with qml and i encountered a strange problem:
I started to use the material fonts as icons.For this i added the Font in cpp:
QFontDatabase::addApplicationFont(":/Ressources/MaterialSymbolsOutlined.ttf");then i try to use it in QML:
ToolButton {
font.family: "MaterialSymbolsOutlined"
font.pixelSize: 24
text: "\ue900"
}here i get a totaly wrong icon displayed, while "\ue8ff" as example works just well.
Do you have got any idea what i'm doing wrong here?
Thanks
Edit:
• Which Qt version are you using? QT 6.10.1
• Which version of QtCreator are you using? 18.01
• Which platform? Windows 11
• How did you install it? Installer -
I would recommend using icons as .svg instead of iconfonts
Buttons support icon themes : https://doc.qt.io/qt-6/qtquickcontrols-icons.html .
Write anicon.themefile pointing to a folder with your icons then you could do the following in your code:ToolButton { icon.name: "zoom_out" } -
Thank you,
I will take look at it. -
Which version of the font is this?
I downloaded the font from the following address and at least for this version, the font family is "Material Symbols Outline" (with spaces), not "MaterialSymbolsOutline":
With this font, U+E900 works fine. Is it possible you used the wrong font name in your application? If so, other fonts on the system will be queried for the characters you request, so you may get one font for U+E900 and another one for U+E8FF, depending on what is available and the order they are queried.
You can get the correct name by calling QFontDatabase::applicationFontFamilies() and pass in the ID that addApplicationFont() returned.