Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt still does not support CSS variables :( aaargh!!
Forum Updated to NodeBB v4.3 + New Features

Qt still does not support CSS variables :( aaargh!!

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 623 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.
  • K Offline
    K Offline
    Kris Revi
    wrote on 7 Aug 2021, 09:07 last edited by
    #1

    As the title states! Qt Qss / css in general does not support CSS2 Variables -.- What are my options here?...

    J 1 Reply Last reply 7 Aug 2021, 09:54
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 7 Aug 2021, 09:17 last edited by
      #2

      Hi
      Yes, CSS2 Variables would be nice for an easy way to manage settings.

      Depending on your actual use case / what you need, some sort of text processing is needed.

      Qstrings ARG function can be used
      https://doc.qt.io/qt-5/qstring.html#arg
      for smaller variable substitution

      However, for more complex replacement, you might want to create a small parser to do the job.

      But it depends on what you needed the vars for. Mine was for colors so I had a lookup table I used
      to set the actual colors from a .ini file.

      K 1 Reply Last reply 7 Aug 2021, 10:03
      1
      • K Kris Revi
        7 Aug 2021, 09:07

        As the title states! Qt Qss / css in general does not support CSS2 Variables -.- What are my options here?...

        J Offline
        J Offline
        JonB
        wrote on 7 Aug 2021, 09:54 last edited by JonB 8 Jul 2021, 09:55
        #3

        @Kris-Revi
        As @mrjj says, you end up needing to "pre-process" some CSS text you write with some kind of "substitution" for your desired variable part.

        I write an external CSS file like usual and put something like

        {
            background-color: #background-color-1#;
            font: #font-2#;
        }
        

        wherever into it. At runtime you read it in, do whatever #...# substitutions and then apply the resulting CSS text to the application or widgets.

        1 Reply Last reply
        1
        • M mrjj
          7 Aug 2021, 09:17

          Hi
          Yes, CSS2 Variables would be nice for an easy way to manage settings.

          Depending on your actual use case / what you need, some sort of text processing is needed.

          Qstrings ARG function can be used
          https://doc.qt.io/qt-5/qstring.html#arg
          for smaller variable substitution

          However, for more complex replacement, you might want to create a small parser to do the job.

          But it depends on what you needed the vars for. Mine was for colors so I had a lookup table I used
          to set the actual colors from a .ini file.

          K Offline
          K Offline
          Kris Revi
          wrote on 7 Aug 2021, 10:03 last edited by
          #4

          @mrjj i need it basicaly everything css related, colors, heigh, width, padding, margin... :)

          M 1 Reply Last reply 7 Aug 2021, 10:18
          0
          • K Kris Revi
            7 Aug 2021, 10:03

            @mrjj i need it basicaly everything css related, colors, heigh, width, padding, margin... :)

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 7 Aug 2021, 10:18 last edited by mrjj 8 Jul 2021, 10:19
            #5

            @Kris-Revi
            Ok :)
            well Style sheet allows multiline comments so you could embed all the tags in top of the file

            /*
            color_top=RGB(0,0,0)
            left_margin=4
            */
            
            ... stylesheet..
            
            

            Then at start up read the file and extract the tags to std::map and use that to replace in the rest of the file.

            I would also make a function that scans the file and output a file with all found Tags so it's easy to
            update the "header" and allows you to invent tags on the fly so to speak.

            1 Reply Last reply
            0

            1/5

            7 Aug 2021, 09:07

            • Login

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