PDA

View Full Version : Is it possible to logically combine dynamic properties in a Qt Stylesheet?



Bebe
26th June 2013, 16:42
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:


MyButton[hasIcon="true"] {background-color: pink;}
MyButton[hasText="true"] {background-color: blue;}

But none of these will set the background to green:


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?

skebanga
28th October 2015, 18:31
Did you ever get anywhere with this?

Added after 21 minutes:

In 5.5 the following works:



MyButton[hasIcon="true"][hasText="true"] {background-color: green;}

Kryzon
28th October 2015, 18:32
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.

skebanga
28th October 2015, 18:38
That's an OR selector

So given the following, if MyButton has hasIcon OR hasText true, it will set background to blue



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



MyButton[hasIcon="true"][hasText="true"] {background-color: blue;}

Kryzon
28th October 2015, 18:57
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.

skebanga
28th October 2015, 18:58
It actually is working - I just just following up on the fact that it was