How to use roboto thin font in qml

前端 未结 3 1396
遇见更好的自我
遇见更好的自我 2021-01-15 15:46

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 u

相关标签:
3条回答
  • 2021-01-15 16:29

    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
    }
    
    0 讨论(0)
  • 2021-01-15 16:33

    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

    0 讨论(0)
  • 2021-01-15 16:47

    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)

    0 讨论(0)
提交回复
热议问题