Is it possible to logically combine dynamic properties in a Qt Stylesheet?
I would like to have logical AND comparison using dynamic properties, but can't figure out the syntax, or if it is even possible.
Lets say I want to do something special to a QPushButton if it has both an icon and text. I know how/when to set the peoperties but can't figure out the stylesheet syntax.
First I set these separate cases fine:
Code:
MyButton[hasIcon="true"] {background-color: pink;}
MyButton[hasText="true"] {background-color: blue;}
But none of these will set the background to green:
Code:
MyButton[hasIcon="true"] MyButton[hasText="true"] {background-color: green;}
MyButton[hasIcon="true"],[hasText="true"] {background-color: green;}
MyButton[hasIcon="true"][hasText="true"] {background-color: green;}
If it isn't possible could someone please let me know so I can stop chasing my tail?
Re: Is it possible to logically combine dynamic properties in a Qt Stylesheet?
Did you ever get anywhere with this?
Added after 21 minutes:
In 5.5 the following works:
Code:
MyButton[hasIcon="true"][hasText="true"] {background-color: green;}
Re: Is it possible to logically combine dynamic properties in a Qt Stylesheet?
Try using the full attribute selectors, separated by a comma. The OP did not try it.
http://stackoverflow.com/a/9536746/4206247
The name of this construct is "group selectors," and seems to be standard CSS.
Re: Is it possible to logically combine dynamic properties in a Qt Stylesheet?
That's an OR selector
So given the following, if MyButton has hasIcon OR hasText true, it will set background to blue
Code:
MyButton[hasIcon="true"],MyButton[hasText="true"] {background-color: blue;}
What OP wanted as an AND selector
Given the following, if MyButton has hasIcon AND hasText true, it will set background to blue
Code:
MyButton[hasIcon="true"][hasText="true"] {background-color: blue;}
Re: Is it possible to logically combine dynamic properties in a Qt Stylesheet?
I understand. Given that the AND selector is valid CSS, it mustn't be something supported by the Qt interpreter right now. Perhaps request it to be implemented?
Just so this doesn't stop you, if you can know which buttons have both text and icon, you can add any custom property to flag the button, like...
myButton.setProperty( "hasIconAndText", true );
And then use a selector for that.
Re: Is it possible to logically combine dynamic properties in a Qt Stylesheet?
It actually is working - I just just following up on the fact that it was