Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to use CSS Vars?
Qt 6.12 LTS is out! See what's new in the release blog

How to use CSS Vars?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 828 Views 2 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.
  • L Offline
    L Offline
    LeandroTeixeira
    wrote on last edited by
    #1

    Hello, i am using .CSS file in my project, and now i want to use CCS Vars. I already tried:
    Test 1:
    @const THEME_DARK_COLOR: #00FFAA
    QLabel#Lbl1 {
    color: @THEME_DARK_COLOR;
    }
    Result: Nothing.

    Test2:
    :root{
    -THEME-DARK-COLOR: #00FFAA;
    }
    QLabel#Lbl1 {
    color: var(-THEME-DARK-COLOR);
    }

    Result: The label does not appear.

    Test 3:
    :root{
    --THEME-DARK-COLOR: #00FFAA;
    }
    QLabel#Lbl1 {
    color: var(--THEME-DARK-COLOR);
    }

    Result: Error on apply the style.css.

    So my question is, how is the right method to use variables on CSS ?
    Thanks a lot.

    JKSHJ JonBJ 2 Replies Last reply
    0
    • L LeandroTeixeira

      Hello, i am using .CSS file in my project, and now i want to use CCS Vars. I already tried:
      Test 1:
      @const THEME_DARK_COLOR: #00FFAA
      QLabel#Lbl1 {
      color: @THEME_DARK_COLOR;
      }
      Result: Nothing.

      Test2:
      :root{
      -THEME-DARK-COLOR: #00FFAA;
      }
      QLabel#Lbl1 {
      color: var(-THEME-DARK-COLOR);
      }

      Result: The label does not appear.

      Test 3:
      :root{
      --THEME-DARK-COLOR: #00FFAA;
      }
      QLabel#Lbl1 {
      color: var(--THEME-DARK-COLOR);
      }

      Result: Error on apply the style.css.

      So my question is, how is the right method to use variables on CSS ?
      Thanks a lot.

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @LeandroTeixeira said in How to use CSS Vars?:

      how is the right method to use variables on CSS ?

      Widget stylesheets only support CSS 2.1. Unfortunately, CSS variables (custom properties) were introduced in CSS 3.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • L LeandroTeixeira

        Hello, i am using .CSS file in my project, and now i want to use CCS Vars. I already tried:
        Test 1:
        @const THEME_DARK_COLOR: #00FFAA
        QLabel#Lbl1 {
        color: @THEME_DARK_COLOR;
        }
        Result: Nothing.

        Test2:
        :root{
        -THEME-DARK-COLOR: #00FFAA;
        }
        QLabel#Lbl1 {
        color: var(-THEME-DARK-COLOR);
        }

        Result: The label does not appear.

        Test 3:
        :root{
        --THEME-DARK-COLOR: #00FFAA;
        }
        QLabel#Lbl1 {
        color: var(--THEME-DARK-COLOR);
        }

        Result: Error on apply the style.css.

        So my question is, how is the right method to use variables on CSS ?
        Thanks a lot.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @LeandroTeixeira said in How to use CSS Vars?:

        So my question is, how is the right method to use variables on CSS ?

        There isn't such a facility in CSS 2.1. It has always been an irritatingly-missing feature, it's interesting to see @JKSH says it has been introduced in CSS 3 (though no use for Qt).

        The usual way to implement this in Qt is to pre-process the CSS (e.g. read from an external) file before applying it in your application. Put things in you can recognise and do necessary replacements.

        1 Reply Last reply
        1
        • L Offline
          L Offline
          LeandroTeixeira
          wrote on last edited by
          #4

          Thanks for the fast response. I will go on with my style.css without using variables.

          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
          • Unsolved