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. how to use the varieties in the qt stylesheet
QtWS25 Last Chance

how to use the varieties in the qt stylesheet

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 184 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.
  • N Offline
    N Offline
    nicker player
    wrote on 21 Aug 2024, 07:22 last edited by
    #1

    once I founded someone use the stylesheet like this:
    @define color_bg_list_msg #ff0000

    QWidget{
    background-color:@color_bg_list_msg;
    }

    In fact.the code above doesnt work for me.I wondered if there is the option to use the vars in the stylesheet.You know the css of the html offers the option what I mentioned.

    J 1 Reply Last reply 21 Aug 2024, 11:59
    0
    • N nicker player
      21 Aug 2024, 07:22

      once I founded someone use the stylesheet like this:
      @define color_bg_list_msg #ff0000

      QWidget{
      background-color:@color_bg_list_msg;
      }

      In fact.the code above doesnt work for me.I wondered if there is the option to use the vars in the stylesheet.You know the css of the html offers the option what I mentioned.

      J Online
      J Online
      JonB
      wrote on 21 Aug 2024, 11:59 last edited by JonB
      #2

      @nicker-player
      So far as I know Qt CSS/QSS (and for that matter same for full CSS in HTML) does not support any kind of "substitution" like this. If you found that in an example somewhere are you sure they did not implement the substitution in their code when reading in the CSS before setting the widget stylesheet from pre-processed code? I use something like your example with my own reading/substitution code if I need "dynamic" CSS/QSS content.

      You know the css of the html offers the option what I mentioned.

      No, I don't think it does. Where is there a reference for HTML/CSS doing any such @define thing? (Seems CSS now has some Using CSS custom properties (variables) which I didn't know about. But it's still not the syntax you show and won't be in QSS anyway.)

      P 1 Reply Last reply 21 Aug 2024, 12:24
      0
      • J JonB
        21 Aug 2024, 11:59

        @nicker-player
        So far as I know Qt CSS/QSS (and for that matter same for full CSS in HTML) does not support any kind of "substitution" like this. If you found that in an example somewhere are you sure they did not implement the substitution in their code when reading in the CSS before setting the widget stylesheet from pre-processed code? I use something like your example with my own reading/substitution code if I need "dynamic" CSS/QSS content.

        You know the css of the html offers the option what I mentioned.

        No, I don't think it does. Where is there a reference for HTML/CSS doing any such @define thing? (Seems CSS now has some Using CSS custom properties (variables) which I didn't know about. But it's still not the syntax you show and won't be in QSS anyway.)

        P Offline
        P Offline
        Pl45m4
        wrote on 21 Aug 2024, 12:24 last edited by Pl45m4
        #3

        @JonB said in how to use the varieties in the qt stylesheet:

        No, I don't think it does. Where is there a reference for HTML/CSS doing any such @define thing? (Seems CSS now has some Using CSS custom properties (variables) which I didn't know about. But it's still not the syntax you show and won't be in QSS anyway.)

        Indeed.
        As the @ character is an unused symbol in C/C++ anyway, this code above isn't about C-languages.
        I think the posted snippet was taken from some PHP/CSS example or something.
        Python also knows @ but used in a different way.

        @nicker-player

        You can treat the Qt Stylesheet as string (QString) and then do this:

        QColor color(Qt::blue);
        QString style("QWidget{ background-color: %1; }").arg( color.name() ); // name = #RRGGBB
        QWidget w;
        w.setStyleSheet(style);
        

        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply
        1

        2/3

        21 Aug 2024, 11:59

        • Login

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