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 1.0k 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.
  • M Offline
    M Offline
    mzimmers
    wrote on 24 Oct 2022, 17:00 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
    • J Offline
      J Offline
      JoeCFD
      wrote on 24 Oct 2022, 18:35 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.

      M 1 Reply Last reply 24 Oct 2022, 18:45
      0
      • J JoeCFD
        24 Oct 2022, 18:35

        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.

        M Offline
        M Offline
        mzimmers
        wrote on 24 Oct 2022, 18:45 last edited by
        #3

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

        J 1 Reply Last reply 24 Oct 2022, 19:44
        0
        • M mzimmers
          24 Oct 2022, 18:45

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

          J Offline
          J Offline
          JoeCFD
          wrote on 24 Oct 2022, 19:44 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

          M 1 Reply Last reply 24 Oct 2022, 21:04
          0
          • J JoeCFD
            24 Oct 2022, 19:44

            @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

            M Offline
            M Offline
            mzimmers
            wrote on 24 Oct 2022, 21:04 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
            • J Offline
              J Offline
              JoeCFD
              wrote on 24 Oct 2022, 21:31 last edited by
              #6

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

              1 Reply Last reply
              1
              • M Offline
                M Offline
                mzimmers
                wrote on 24 Oct 2022, 22:00 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...

                J 1 Reply Last reply 25 Oct 2022, 14:11
                0
                • M mzimmers
                  24 Oct 2022, 22:00

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

                  J Offline
                  J Offline
                  JoeCFD
                  wrote on 25 Oct 2022, 14:11 last edited by JoeCFD
                  #8

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

                  M 1 Reply Last reply 25 Oct 2022, 15:45
                  1
                  • J JoeCFD
                    25 Oct 2022, 14:11

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

                    M Offline
                    M Offline
                    mzimmers
                    wrote on 25 Oct 2022, 15:45 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

                    1/9

                    24 Oct 2022, 17:00

                    • Login

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