need a slick way of "hiding" my FontLoaders
-
wrote on 15 Nov 2022, 22:51 last edited by
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):
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...
-
wrote on 15 Nov 2022, 22:59 last edited by JoeCFD
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>
-
wrote on 15 Nov 2022, 23:44 last edited by mzimmers
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...
-
wrote on 16 Nov 2022, 00:23 last edited by JoeCFD
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 -
wrote on 16 Nov 2022, 16:31 last edited by
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...
-
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...
wrote on 16 Nov 2022, 16:40 last edited by@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} ) -
@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} )wrote on 16 Nov 2022, 16:46 last edited by@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?
-
@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?
wrote on 16 Nov 2022, 16:51 last edited by JoeCFD@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. -
wrote on 16 Nov 2022, 17:03 last edited by mzimmers
OK then - here's my (partial) project layout:
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...
-
wrote on 16 Nov 2022, 17:34 last edited by
@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.
7/11