How to use roboto thin font in qml

霸气de小男生 提交于 2020-01-30 08:16:51

问题


I am trying to use robot thin font in QML in Linux.I have install bold,thin and light fonts on ubuntu. Other programs like openoffice shows me only roboto. How do i get to use roboto thin or light in qml?


回答1:


You can bundle the font files with your application and then use FontLoader component to load the version you want and use these in QML.

This component also exist for QtQuick 1.0 as it was introduced in Qt 4.7 FontLoader




回答2:


FontLoader will solve the issue for Light Roboto but not for Thin as it's not a sported weight. Remember to call font.weight: Font.Light in the text elements were you want to use Light weight.

You will need to repackage the Roboto-thin.ttf as a new font and then import it back with FontLoader, (no need for the font.weight: Font.Light call in this case)




回答3:


AlexB's answer is correct, and has cost me too long struggling why it didn't work.

For those wondering why their Roboto-Light font looks like Roboto-Bold, heres how to fix it:

FontLoader
{
   id: robotoLight
   source: "../fonts/Roboto/Roboto-Light.ttf"
}

Text
{
   text: "This text is Roboto-Light"
   font.family: robotoLight.name
   font.weight: Font.Light   // this is necessary or else it'll look like Roboto-Bold
}


来源:https://stackoverflow.com/questions/19654352/how-to-use-roboto-thin-font-in-qml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!