Results 1 to 2 of 2

Thread: How to define a variable in QSS

  1. #1
    Join Date
    Aug 2013
    Posts
    27
    Thanks
    3

    Default How to define a variable in QSS

    Hi,
    As title, I'd like to modify some elements in QSS file with same value, for example, in my qss, I use these code to set QCombobox and popup item's height to 80
    QComboBox QAbstractItemView::item { min-height: 80px; min-width: 60px; }
    QComboBox {min-height: 80px; min-width: 60px;}
    If I need change min-height to 60, I have to update both two min-heights to 60.

    Is there any way to define a variable to only change the value once?
    I want my code to be this style:
    comboxMin-height = 60px --------------> comboxMin-height is a variable.
    QComboBox QAbstractItemView::item { min-height: $(comboxMin-height); min-width: 60px; }
    QComboBox {min-height: $(comboxMin-height); min-width: 60px;}

  2. #2
    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 define a variable in QSS

    Not in the automagic fashion you imagine, but you are free to build the style string and then apply it:
    Qt Code:
    1. const QString styleString(
    2. "QComboBox QAbstractItemView::item { min-height: %1; min-width: 60px; } "
    3. "QComboBox {min-height: %1; min-width: %2px;} "
    4. );
    5. setStyle(styleString.arg("60px").arg(75));
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to ChrisW67 for this useful post:

    Abel (29th April 2014)

Similar Threads

  1. Define a QRegExp
    By aaditya190 in forum Newbie
    Replies: 8
    Last Post: 2nd December 2013, 06:29
  2. Does not define type
    By Atomic_Sheep in forum General Programming
    Replies: 4
    Last Post: 22nd July 2013, 15:04
  3. tr with #define..it can work?
    By mattia in forum Newbie
    Replies: 9
    Last Post: 4th February 2008, 11:15
  4. #define MYCLASS_H ?
    By bnilsson in forum General Programming
    Replies: 1
    Last Post: 3rd February 2008, 10:50
  5. where should i put #define in QtDesigner?
    By nass in forum Qt Tools
    Replies: 1
    Last Post: 16th October 2006, 15:52

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.