Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Brainstorm
  4. getting QML to report on font used
QtWS25 Last Chance

getting QML to report on font used

Scheduled Pinned Locked Moved Solved Brainstorm
4 Posts 2 Posters 744 Views
  • 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, 00:58 last edited by
    #1

    Hi all -

    I've been struggling with a font that I'm using through the resource system. I'm not getting any runtime errors, but my various attempts to use the font aren't showing up. Is there some QML magic that will allow me to report on the font being used, through the console.log() facility or something?

    Thanks...

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JKSH
      Moderators
      wrote on 24 Oct 2022, 01:32 last edited by
      #2

      @mzimmers said in getting QML to report on font used:

      I've been struggling with a font that I'm using through the resource system. I'm not getting any runtime errors, but my various attempts to use the font aren't showing up.

      Can you please describe your various attempts?

      Is there some QML magic that will allow me to report on the font being used, through the console.log() facility or something?

      Something like this:

      ApplicationWindow {
          id: window
          visible: true
      
          // ...
      
          Component.onCompleted: console.log(window.font)
      }
      

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      2
      • M Offline
        M Offline
        mzimmers
        wrote on 24 Oct 2022, 01:43 last edited by mzimmers
        #3

        @JKSH said in getting QML to report on font used:

        Component.onCompleted: console.log(window.font)

        That's going to be helpful going forward; thanks.

        To answer your question, I've:

        1. created a resource file and populated it with the fonts I want
        2. added the resource file to my CMakeLists.txt (which also includes:
        set(CMAKE_AUTORCC ON)
        
        
        1. put this code in the QML file I'm trying to manipulate:
            font.family: "Rubik"
            font.pixelSize: 24
            font.weight: Font.Bold
        

        I think I'm getting the font loaded, based on your telltale suggestion:

        qml: QFont(Rubik,-1,24,5,700,0,0,0,0,0,0,0,0,0,0,1)
        

        But my Font.Bold isn't "taking."

        EDIT:

        I also have this code in my main.qml:

           FontLoader {
               id: rubikItalic
               source: "qrc:/fonts/Rubik/Rubik-Italic-VariableFont_wght.ttf"
           }
           FontLoader {
               id: rubik
               source: "qrc:/fonts/Rubik/Rubik-VariableFont_wght.ttf"
           }
        

        In addition to the two variable .ttf files in this font, there are a number of static fonts, but for now I'm assuming that I don't need to load those.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mzimmers
          wrote on 24 Oct 2022, 16:35 last edited by
          #4

          Since @JKSH answered my original question, I'm marking this as solved. I'll bring up my other questions in a new topic with a more accurate title.

          1 Reply Last reply
          0

          4/4

          24 Oct 2022, 16:35

          • Login

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