How to do smart color and style management
-
Hello,
I made an app that use some colors that not "standard". I use those non "standard" colors in different qml file and each time I need to change the color I have to find every place I use it. I find it complicated and not a good solution.
What is the best way to handle this at a same place ?
The idea would be to have some kind of file where I declare color such as :buttonColor = "#ffffff" menuColor = "#00ff00" ...
and then be able to use "buttonColor" and "menuColor" on my qml files.
Thank you in advance for your help.
-
Hello,
I made an app that use some colors that not "standard". I use those non "standard" colors in different qml file and each time I need to change the color I have to find every place I use it. I find it complicated and not a good solution.
What is the best way to handle this at a same place ?
The idea would be to have some kind of file where I declare color such as :buttonColor = "#ffffff" menuColor = "#00ff00" ...
and then be able to use "buttonColor" and "menuColor" on my qml files.
Thank you in advance for your help.
-
@DavidM29 hi,
see Qml Styling -
@LeLev
Thank you for your answer I think the singleton version is what I'm looking for.
Do you have any complete exemple in your mind ? If no, I'll be looking a bit more on the web for this. -
@DavidM29
the example in that page will show you how to create your Singleton file and how to use it in the other files. I don't have another complete example in mind right now -
Hi,
As suggested in the Registering Non-Instantiable Types part of the
Defining QML Types from C++ chapter
of Qt's documentation, you can create a theme type and provide there all the colours you want to use through your application. Then if you'd like to change something, you can simply modify your theme object and you're done. -
@LeLev
My issue is the use of qmldir file I've never used any file of this kind and don't know where to put it and how to use it.@DavidM29 said in How to do smart color and style management:
My issue is the use of qmldir file I've never used any file of this kind and don't know where to put it and how to use it.
Simply create a new file called qmldir with no extension (not .txt ..) and put it in your project folder near your style singleton file.
If your qml singleton file name is MyStyle.qml then qmldir should contain singleton Style 1.0 MyStyle.qml
Now you can import and use your Singleton in your qml components
import "."
https://wiki.qt.io/Qml_Styling : Approach 2: Style Singleton
-
@DavidM29 said in How to do smart color and style management:
My issue is the use of qmldir file I've never used any file of this kind and don't know where to put it and how to use it.
Simply create a new file called qmldir with no extension (not .txt ..) and put it in your project folder near your style singleton file.
If your qml singleton file name is MyStyle.qml then qmldir should contain singleton Style 1.0 MyStyle.qml
Now you can import and use your Singleton in your qml components
import "."
https://wiki.qt.io/Qml_Styling : Approach 2: Style Singleton
-
@DavidM29 said in How to do smart color and style management:
My issue is the use of qmldir file I've never used any file of this kind and don't know where to put it and how to use it.
Simply create a new file called qmldir with no extension (not .txt ..) and put it in your project folder near your style singleton file.
If your qml singleton file name is MyStyle.qml then qmldir should contain singleton Style 1.0 MyStyle.qml
Now you can import and use your Singleton in your qml components
import "."
https://wiki.qt.io/Qml_Styling : Approach 2: Style Singleton