Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to apply stylesheet only to parent?
Forum Updated to NodeBB v4.3 + New Features

How to apply stylesheet only to parent?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.5k Views
  • 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.
  • R Offline
    R Offline
    Roberrt
    wrote on last edited by
    #1

    Is there another way to apply a StyleSheet only to the parent widget ignoring her childrens than using her object name?

    #widget_1 {
       // ....
    }
    

    This way if i change the object name the stylesheet will not work anymore, i wonder if there's any other option?

    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by JoeCFD
      #2

      set style sheet with object name of the parent for example groupBoxSettings
      QString settingStyle = " QGroupBox#groupBoxSettings {
      background-color: rgb(248,248,248);
      border: 1px solid rgb(170, 170, 255);
      border-radius: 3px;
      border-color:rgb(170, 170, 255);
      }";

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Roberrt
        wrote on last edited by
        #3

        I'm searching for another option than using the object name

        JonBJ 1 Reply Last reply
        0
        • R Roberrt

          I'm searching for another option than using the object name

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Roberrt
          Other than the #objectName selector the only other way I see is the .ClassName one. For that you would need to make your desired target widget(s) be of a derived class named ClassName you would need to create. See https://doc.qt.io/qt-6/stylesheet-syntax.html#selector-types

          Class Selector .QPushButton Matches instances of QPushButton, but not of its subclasses.
          This is equivalent to *[class~="QPushButton"].

          Having said this: it only talks about not applying to subclasses, not children. So I don't know that this is the right approach. Mind, I do not actually see where the documentation states that #objectName selectors only apply to that widget and not its children, so it's guesswork.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved