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. Is there any method to define a variable in QSS file?

Is there any method to define a variable in QSS file?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 1.5k 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.
  • brucezcgB Offline
    brucezcgB Offline
    brucezcg
    wrote on last edited by
    #1

    As the topic, how to define a variable in qss.
    just like #define FONT_SIZE 16px

    JonBJ 1 Reply Last reply
    0
    • brucezcgB brucezcg

      As the topic, how to define a variable in qss.
      just like #define FONT_SIZE 16px

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

      @brucezcg
      Nope (nor in CSS) :( .

      You won't like this, but I have faced this problem. I do my work direct from Qt widgets, no QML/Qt Quick, so I don't know whether this is useful/applicable to you or not. I actually "pre-process" my QSS stylesheet file(s), before handing them off to QtWidgets.QApplication.instance().setStyleSheet(css) in code. So for example example my primary QSS file starts with:

      /* Set the base font size for all widgets */
      * {
          font-size: <FONT_SIZE>pt;
      }
      

      and my code, having read the file content into css variable, is like:

          # substitute all "<FONT_SIZE>" with the actual font size wanted
          fontSize = Settings.current().getDefaultFontSize()
          css = css.replace("<FONT_SIZE>", fontSize)
          biggerFontSize = Settings.current().getDefaultBiggerFontSize()
          css = css.replace("<BIGGER_FONT_SIZE>", biggerFontSize)
          ...
          QtWidgets.QApplication.instance().setStyleSheet(css)
      
      brucezcgB 1 Reply Last reply
      2
      • JonBJ JonB

        @brucezcg
        Nope (nor in CSS) :( .

        You won't like this, but I have faced this problem. I do my work direct from Qt widgets, no QML/Qt Quick, so I don't know whether this is useful/applicable to you or not. I actually "pre-process" my QSS stylesheet file(s), before handing them off to QtWidgets.QApplication.instance().setStyleSheet(css) in code. So for example example my primary QSS file starts with:

        /* Set the base font size for all widgets */
        * {
            font-size: <FONT_SIZE>pt;
        }
        

        and my code, having read the file content into css variable, is like:

            # substitute all "<FONT_SIZE>" with the actual font size wanted
            fontSize = Settings.current().getDefaultFontSize()
            css = css.replace("<FONT_SIZE>", fontSize)
            biggerFontSize = Settings.current().getDefaultBiggerFontSize()
            css = css.replace("<BIGGER_FONT_SIZE>", biggerFontSize)
            ...
            QtWidgets.QApplication.instance().setStyleSheet(css)
        
        brucezcgB Offline
        brucezcgB Offline
        brucezcg
        wrote on last edited by
        #3

        @JonB Thanks, Let me try.

        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