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. need a slick way of "hiding" my FontLoaders
Forum Updated to NodeBB v4.3 + New Features

need a slick way of "hiding" my FontLoaders

Scheduled Pinned Locked Moved Solved Brainstorm
11 Posts 2 Posters 1.9k 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.
  • JoeCFDJ Offline
    JoeCFDJ Offline
    JoeCFD
    wrote on last edited by JoeCFD
    #2

    Put it into another fonts.qrc file? They can be accessed anywhere in your app.

    <RCC>
        <qresource prefix="/fonts">
            <file alias="rubikblack">resources/fonts/Rubik-Black.ttf</file>
        </qresource>
    <RCC>
    
    1 Reply Last reply
    1
    • mzimmersM Offline
      mzimmersM Offline
      mzimmers
      wrote on last edited by mzimmers
      #3

      I already have a fonts.qrc file:

      <RCC>
          <qresource prefix="/">
              <file>fonts/Rubik/static/Rubik-Black.ttf</file>
      

      Is it sufficient if I just change the entries to what you posted, or do I actually need separate qrc files? Also, what is the meaning of "resources" in the file entry you posted?

      EDIT:

      It builds if I change the entries to this:

      <RCC>
          <qresource prefix="/">
              <file alias="rubik_semibold">fonts/Rubik/static/Rubik-SemiBold.ttf</file>
      

      So, how do I reference that font in my QML? When I was using FontLoader, I did it like this:

      Text {
          id: localTime
          text: clock.time
          font.family: rubik_semibold.font.family
          ....
      

      Thanks...

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

        resources is only a dir name and can be anything. I put images, qml and font files in this dir.
        it is better to separate qrc files for maintenance purpose. Otherwise, one qrc file can be too big.
        It is better to define your custom font at a place for general settings. Then it can be accessed anywhere in your app.
        https://stackoverflow.com/questions/68000684/qml-fontloader-not-loading-the-custom-font

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

          When I create my assets subdirectory, Creator tells me I need a CMakeLists.txt file in it. What should this contain - I know the contents don't represent a separate project.

          Thanks...

          JoeCFDJ 1 Reply Last reply
          0
          • mzimmersM mzimmers

            When I create my assets subdirectory, Creator tells me I need a CMakeLists.txt file in it. What should this contain - I know the contents don't represent a separate project.

            Thanks...

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

            @mzimmers
            is this related to qrc files?
            If yes, add this to your cmake file
            file( GLOB_RECURSE MY_RCs "${CMAKE_CURRENT_SOURCE_DIR}/resources/*.qrc" )
            ============RECURSE is such a bad word, not sure who made it====

            add_executable( ${PROJECT_NAME}
            ...
            ${MY_RCs} )

            mzimmersM 1 Reply Last reply
            0
            • JoeCFDJ JoeCFD

              @mzimmers
              is this related to qrc files?
              If yes, add this to your cmake file
              file( GLOB_RECURSE MY_RCs "${CMAKE_CURRENT_SOURCE_DIR}/resources/*.qrc" )
              ============RECURSE is such a bad word, not sure who made it====

              add_executable( ${PROJECT_NAME}
              ...
              ${MY_RCs} )

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

              @JoeCFD I'm trying to follow the example in the SO article you posted - the solution uses an "assets" directory containing the Style.qml that holds the FontLoaders. (I think his style directory is equivalent to your resources directory.)

              I'm not sure whether I even need a CMakeLists.txt file for this directory, but I don't know another way to expose the directory to CMake. Maybe I don't have to, if the files are all properly prefixed with the directory name in the .qml code?

              JoeCFDJ 1 Reply Last reply
              0
              • mzimmersM mzimmers

                @JoeCFD I'm trying to follow the example in the SO article you posted - the solution uses an "assets" directory containing the Style.qml that holds the FontLoaders. (I think his style directory is equivalent to your resources directory.)

                I'm not sure whether I even need a CMakeLists.txt file for this directory, but I don't know another way to expose the directory to CMake. Maybe I don't have to, if the files are all properly prefixed with the directory name in the .qml code?

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

                @mzimmers no, you do not need cmake file for the dirs of qrc files.
                file( GLOB_RECURSE MY_RCs "${CMAKE_CURRENT_SOURCE_DIR}/resources/*.qrc" )
                ${CMAKE_CURRENT_SOURCE_DIR}/resources or ${CMAKE_CURRENT_SOURCE_DIR}/assets is the path for qrc files.
                I have a qml.qrc and an images.qrc. cmake works fine.

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

                  OK then - here's my (partial) project layout:
                  assets.PNG

                  I have a subfolder assets with two files, along the lines of the SO example:

                  // assets.qrc
                  <RCC>
                      <qresource prefix="/assets">
                           <file alias="qmldir">assets/qmldir</file>
                           <file alias="Style.qml">assets/Style.qml</file>
                      </qresource>
                  </RCC>
                  
                  // assets/qmldir
                  module assets
                  singleton Style 1.0 Style.qml
                  

                  In the QML file where I wish to use the custom font, I have this line:

                  import assets 1.0 // subdirectory for custom fonts
                  

                  and I'm getting an error "QML module not found (assets)."

                  I think I'm close on this, but there seems to be a missing step. Does my main qmldir file need to reference the assets/qmldir?

                  EDIT:

                  I realized I needed to add assets/Style.qml to my main CMakeLists.txt file. That error is gone now. I'm still not able to use the Style alias yet, though.

                  Please disregard the line above; the error still exists.

                  Thanks...

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

                    https://doc.qt.io/qt-6/cmake-build-reusable-qml-module.html and https://doc.qt.io/qtcreator/quick-converting-ui-projects.html

                    mzimmersM 1 Reply Last reply
                    0
                    • JoeCFDJ JoeCFD

                      https://doc.qt.io/qt-6/cmake-build-reusable-qml-module.html and https://doc.qt.io/qtcreator/quick-converting-ui-projects.html

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

                      @JoeCFD I found the problem - I needed this line in my main.cpp:

                          qmlRegisterSingletonType( QUrl( "qrc:/assets/Style.qml" ), "styles.stylesheet", 1, 0, "Style" );
                      

                      Not sure how the SO example worked without this, but...it seems to be working for me now.

                      Thanks for all the assistance on this.

                      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