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

need a slick way of "hiding" my FontLoaders

Scheduled Pinned Locked Moved Solved Brainstorm
11 Posts 2 Posters 1.3k 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 15 Nov 2022, 22:51 last edited by
    #1

    Hi all -

    So, according to the response to this bug report I filed, variable fonts don't work with Windoze, so I need to fall back on the fixed fonts. No huge deal, but since there are a lot of these files (these just for one font, and I'll be using several):
    fonts.PNG
    I'd rather not have my main.qml cluttered with tons of Fontloader instances. If I put them in another file, though, they're not accessible to other areas of my app. Any ideas on how to get around this?

    Thanks...

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JoeCFD
      wrote on 15 Nov 2022, 22:59 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
      • M Offline
        M Offline
        mzimmers
        wrote on 15 Nov 2022, 23:44 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
        • J Offline
          J Offline
          JoeCFD
          wrote on 16 Nov 2022, 00:23 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
          • M Offline
            M Offline
            mzimmers
            wrote on 16 Nov 2022, 16:31 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...

            J 1 Reply Last reply 16 Nov 2022, 16:40
            0
            • M mzimmers
              16 Nov 2022, 16:31

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

              J Offline
              J Offline
              JoeCFD
              wrote on 16 Nov 2022, 16:40 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} )

              M 1 Reply Last reply 16 Nov 2022, 16:46
              0
              • J JoeCFD
                16 Nov 2022, 16:40

                @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} )

                M Offline
                M Offline
                mzimmers
                wrote on 16 Nov 2022, 16:46 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?

                J 1 Reply Last reply 16 Nov 2022, 16:51
                0
                • M mzimmers
                  16 Nov 2022, 16:46

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

                  J Offline
                  J Offline
                  JoeCFD
                  wrote on 16 Nov 2022, 16:51 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
                  • M Offline
                    M Offline
                    mzimmers
                    wrote on 16 Nov 2022, 17:03 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
                    • J Offline
                      J Offline
                      JoeCFD
                      wrote on 16 Nov 2022, 17:18 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

                      M 1 Reply Last reply 16 Nov 2022, 17:34
                      0
                      • J JoeCFD
                        16 Nov 2022, 17:18

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

                        M Offline
                        M Offline
                        mzimmers
                        wrote on 16 Nov 2022, 17:34 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

                        10/11

                        16 Nov 2022, 17:18

                        • Login

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