PDA

View Full Version : How to define a variable in QSS



Abel
29th April 2014, 04:55
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;}

ChrisW67
29th April 2014, 06:11
Not in the automagic fashion you imagine, but you are free to build the style string and then apply it:


const QString styleString(
"QComboBox QAbstractItemView::item { min-height: %1; min-width: 60px; } "
"QComboBox {min-height: %1; min-width: %2px;} "
);
setStyle(styleString.arg("60px").arg(75));