Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. proper use of FontLoader (unable to set font weight)
Forum Updated to NodeBB v4.3 + New Features

proper use of FontLoader (unable to set font weight)

Scheduled Pinned Locked Moved Solved QML and Qt Quick
9 Posts 2 Posters 994 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by mzimmers
    #1

    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.

    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by JoeCFD
      #2

      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-prop

      font.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.

      mzimmersM 1 Reply Last reply
      0
      • JoeCFDJ JoeCFD

        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-prop

        font.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.

        mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #3

        @JoeCFD I don't understand - when you say "Try other choices," what are you referring to?

        JoeCFDJ 1 Reply Last reply
        0
        • mzimmersM mzimmers

          @JoeCFD I don't understand - when you say "Try other choices," what are you referring to?

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by
          #4

          @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

          mzimmersM 1 Reply Last reply
          0
          • JoeCFDJ JoeCFD

            @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

            mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #5

            @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.

            1 Reply Last reply
            0
            • JoeCFDJ Offline
              JoeCFDJ Offline
              JoeCFD
              wrote on last edited by
              #6

              https://bugreports.qt.io/browse/QTBUG-94835?jql=issuetype %3D Bug AND text ~ "font weight"

              1 Reply Last reply
              1
              • mzimmersM Offline
                mzimmersM Offline
                mzimmers
                wrote on last edited by
                #7

                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...

                JoeCFDJ 1 Reply Last reply
                0
                • mzimmersM mzimmers

                  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...

                  JoeCFDJ Offline
                  JoeCFDJ Offline
                  JoeCFD
                  wrote on last edited by JoeCFD
                  #8

                  @mzimmers https://wiki.archlinux.org/title/Microsoft_fonts#Legacy_packages
                  may be or may not be.

                  mzimmersM 1 Reply Last reply
                  1
                  • JoeCFDJ JoeCFD

                    @mzimmers https://wiki.archlinux.org/title/Microsoft_fonts#Legacy_packages
                    may be or may not be.

                    mzimmersM Offline
                    mzimmersM Offline
                    mzimmers
                    wrote on last edited by
                    #9

                    @JoeCFD thanks for the link. I think there's something more at play here -- I've added a couple comments to the bug report you linked above, and will pursue this issue with that team. Marking this as closed. Thanks for the help.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved