Results 1 to 4 of 4

Thread: How to declare variables in Qt Stylesheets

  1. #1
    Join Date
    Feb 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to declare variables in Qt Stylesheets

    Hi all,

    Anybody knows if it is possible to create variables in a Qt Stylesheet (.qss)?

    For instance, I know CSS accepts the following:

    Qt Code:
    1. @variables {
    2. myColour: #fe8d12;
    3. }
    4.  
    5. div {
    6. background-color: var(myColour);
    7. }
    To copy to clipboard, switch view to plain text mode 

    I tried the same in qt (with QWidget instead of div) with no avail.

    Any suggestions?
    If it is not possible it would be a nice feature request.

  2. #2

    Default Re: How to declare variables in Qt Stylesheets

    I want know to, how i can declare variables in Qt Stylesheets. So it's impossible ?

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to declare variables in Qt Stylesheets

    ... another zombie thread.

    That ability is certainly not in the Qt Style Sheets docs. If you've tried it and it doesn't work then it doesn't work. You can, of course, dynamically create style sheets:
    Qt Code:
    1. QString styleSheet(
    2. "QLabel { background-color: %1; color: %2; }"
    3. "QLineEdit { background-color: %1; }"
    4. );
    5. ...
    6. QString varBGColour("yellow");
    7. QString varFGColour("steelblue");
    8. setStyleSheet( styleSheet.arg(varBGColour).arg(varFGColour) );
    To copy to clipboard, switch view to plain text mode 
    I'd make sure it cannot be done with inheritance first.

  4. #4

    Default Re: How to declare variables in Qt Stylesheets

    Yes, i know that i can dynamically create style sheets. But more better when you edit style sheet in designer, (not from code).

Similar Threads

  1. how to declare a global variable right
    By Cruz in forum Newbie
    Replies: 13
    Last Post: 16th February 2010, 17:25
  2. Replies: 2
    Last Post: 17th December 2009, 15:01
  3. Problem to declare a stl map - Q_DECLARE_METATYPE
    By Althor in forum Qt Programming
    Replies: 5
    Last Post: 9th December 2008, 10:41
  4. How to declare signal in qt designer??
    By hesummar in forum Qt Tools
    Replies: 4
    Last Post: 27th October 2006, 14:31
  5. declare in designer
    By mickey in forum Newbie
    Replies: 1
    Last Post: 23rd February 2006, 20:24

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.