Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to do smart color and style management

How to do smart color and style management

Scheduled Pinned Locked Moved Solved QML and Qt Quick
9 Posts 3 Posters 1.2k 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.
  • D Offline
    D Offline
    DavidM29
    wrote on last edited by DavidM29
    #1

    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.

    ODБOïO 1 Reply Last reply
    0
    • D DavidM29

      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.

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      @DavidM29 hi,
      see Qml Styling

      D 1 Reply Last reply
      2
      • ODБOïO ODБOï

        @DavidM29 hi,
        see Qml Styling

        D Offline
        D Offline
        DavidM29
        wrote on last edited by
        #3

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

        ODБOïO 1 Reply Last reply
        0
        • D DavidM29

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

          ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by
          #4

          @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

          D 1 Reply Last reply
          0
          • ODБOïO ODБOï

            @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

            D Offline
            D Offline
            DavidM29
            wrote on last edited by
            #5

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

            ODБOïO 1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              2
              • D DavidM29

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

                ODБOïO Offline
                ODБOïO Offline
                ODБOï
                wrote on last edited by
                #7

                @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

                D 2 Replies Last reply
                2
                • ODБOïO ODБOï

                  @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

                  D Offline
                  D Offline
                  DavidM29
                  wrote on last edited by
                  #8

                  @LeLev
                  Perfect ! Thank you

                  1 Reply Last reply
                  0
                  • ODБOïO ODБOï

                    @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

                    D Offline
                    D Offline
                    DavidM29
                    wrote on last edited by
                    #9
                    This post is deleted!
                    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