In QSS is there a "not" selector?



  • In my application stylesheet I have:

    QPushButton {
       ...
    }
    

    with a fair number of styles. I have many different classes derived from QPushButton, all of which do want to inherit the styles. Except for one class (of course!)...

    Did I spot somewhere that there is some kind of not selector-qualifier in QSS? Maybe like:

    QPushButton[not ...] {
       ...
    }
    

    I can't use .QPushButton (leading "dot") selector, as I do want loads of other QPushButton-derived classes to inherit, just not one particular class.


  • Moderators

    @JonB said in In QSS is there a "not" selector?:

    with a fair number of styles. I have many different classes derived from QPushButton, all of which do want to inherit the styles

    See the supported selector types.
    Only pseudo states may be negated using the exclamation mark. For the rest you have to trick with smart attribute selectors or derived class selectors, etc.

    Since you derived from QPushButton and only want one derived class to appear differently, add a style definition for your derived class and reset all properties used in the QPushButton-style.



  • @raven-worx
    Thanks, I had read that link, that's where I could not see a not, yet I thought I had read somewhere else that one existed. But you have said that would only be for pseudo-states, so I don't see that would help.

    add a style definition for your derived class and reset all properties used in the QPushButton-style

    I don't understand what you mean? I want no properties which might have been applied to the generic QPushButton style elsewhere in some style file. Since end-users can (deliberately) edit the styles for QPushButton in the stylesheet files, I have no idea "what to cancel/override" for my SpecialPushButton class, if that is what you mean? That's why I am searching for a syntax which they can be applied to the generic QPushButton style specification to tell it not to apply whatever styles specified to the SpecialPushButton class.


  • Moderators

    @JonB
    Qt stylesheet follows the CSS2 syntax, where as the not keyword is CSS3 specific.
    Unfortunately there is no comparison for "inequality" in the property selectors defined.

    To come back to your problem, thats the only solution i see:

    QPushButton {
         prop: ....;
    }
    
    SpecialPushButton {
        prop: resettedValue;
    }
    


  • @raven-worx
    I see, thanks for clarifying.

    And I think you understand that unfortunately I don't know which props to use (because user could have set any). Nor for that matter would I know what resettedValues to use, as I don't know the original value and QSS doesn't have prop: initial; or prop: inherit; like CSS does.

    I do use the ~= operator elsewhere, like QPushButton[prop ~= "value"], but it doesn't look like there is a !~= operator, which would have done me.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.