Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved In QSS is there a "not" selector?

    General and Desktop
    2
    5
    2380
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • JonB
      JonB last edited by

      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.

      raven-worx 1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators @JonB last edited by

        @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.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        JonB 1 Reply Last reply Reply Quote 3
        • JonB
          JonB @raven-worx last edited by JonB

          @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.

          raven-worx 1 Reply Last reply Reply Quote 0
          • raven-worx
            raven-worx Moderators @JonB last edited by

            @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;
            }
            

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            JonB 1 Reply Last reply Reply Quote 0
            • JonB
              JonB @raven-worx last edited by

              @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.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post