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. qss and children objects
Forum Updated to NodeBB v4.3 + New Features

qss and children objects

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 3 Posters 1.9k Views 1 Watching
  • 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.
  • magrifM Offline
    magrifM Offline
    magrif
    wrote on last edited by
    #1

    In Designer I have created QWidget with child QPushButton within that have names widget and btn accordingly. At widget I have set up qss:

    #widget {
      background-color: red;
    }
    
    #widget:hover {
      background-color: green;
    }
    
    #widget:hover > #btn {
      background-color: rgb(255, 0, 0);
    }
    
    #widget:!hover > #btn {
      background-color: rgb(0, 0, 255);
    }
    

    But color changes only at widget. Why? How its syntax is correct?

    JonBJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Your error description is not clear. Do you mean your stylesheet only applies to your widget named widget ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      magrifM 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Your error description is not clear. Do you mean your stylesheet only applies to your widget named widget ?

        magrifM Offline
        magrifM Offline
        magrif
        wrote on last edited by
        #3

        @SGaist
        Hi,
        yes, I thought QPushButton should change the self background color too depending on the hover state of widget.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          There's no reason for that. From what you wrote, you applied that stylesheet on "widget".

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          magrifM 1 Reply Last reply
          0
          • SGaistS SGaist

            There's no reason for that. From what you wrote, you applied that stylesheet on "widget".

            magrifM Offline
            magrifM Offline
            magrif
            wrote on last edited by
            #5

            @SGaist
            But btn is child of widget, and hence syntax > #btn is mean third and fourth rules applies to btn. Or I something missed?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Please show your code, I have misunderstood your description.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              magrifM 1 Reply Last reply
              0
              • SGaistS SGaist

                Please show your code, I have misunderstood your description.

                magrifM Offline
                magrifM Offline
                magrif
                wrote on last edited by magrif
                #7

                @SGaist

                QWidget* widget = new QWidget;
                widget->setObjectName("widget");
                QPushButton* btn = new QPushButton(widget);
                btn->setObjectName("btn");
                widget->setStyleSheet("...see above...");
                
                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Which version of Qt ?
                  On which platform ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  magrifM 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Which version of Qt ?
                    On which platform ?

                    magrifM Offline
                    magrifM Offline
                    magrif
                    wrote on last edited by
                    #9

                    @SGaist
                    Qt 5.15.1
                    Windows 10 (amd64)

                    1 Reply Last reply
                    0
                    • magrifM magrif

                      In Designer I have created QWidget with child QPushButton within that have names widget and btn accordingly. At widget I have set up qss:

                      #widget {
                        background-color: red;
                      }
                      
                      #widget:hover {
                        background-color: green;
                      }
                      
                      #widget:hover > #btn {
                        background-color: rgb(255, 0, 0);
                      }
                      
                      #widget:!hover > #btn {
                        background-color: rgb(0, 0, 255);
                      }
                      

                      But color changes only at widget. Why? How its syntax is correct?

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

                      @magrif said in qss and children objects:

                      #widget:hover > #btn {
                        background-color: rgb(255, 0, 0);
                      }
                      

                      Did you try

                      QWidget:hover > QPushButton  {
                        background-color: rgb(255, 0, 0);
                      }
                      

                      just in case?

                      And I would start out by testing changing the button without specifying hover to eliminate that from being the issue.

                      #widget > #btn { ...
                      /* or */
                      QWidget > QPushButton { ...
                      

                      BTW, according to https://doc.qt.io/qt-5/stylesheet-syntax.html#selector-types I do not see that #widget is a legal selector in QSS? It only shows accepting QWidget#widget? EDIT Oh you said in Designer, maybe it gets translated from what you show? Bear that in mind for my suggestions above.

                      magrifM 1 Reply Last reply
                      0
                      • JonBJ JonB

                        @magrif said in qss and children objects:

                        #widget:hover > #btn {
                          background-color: rgb(255, 0, 0);
                        }
                        

                        Did you try

                        QWidget:hover > QPushButton  {
                          background-color: rgb(255, 0, 0);
                        }
                        

                        just in case?

                        And I would start out by testing changing the button without specifying hover to eliminate that from being the issue.

                        #widget > #btn { ...
                        /* or */
                        QWidget > QPushButton { ...
                        

                        BTW, according to https://doc.qt.io/qt-5/stylesheet-syntax.html#selector-types I do not see that #widget is a legal selector in QSS? It only shows accepting QWidget#widget? EDIT Oh you said in Designer, maybe it gets translated from what you show? Bear that in mind for my suggestions above.

                        magrifM Offline
                        magrifM Offline
                        magrif
                        wrote on last edited by magrif
                        #11

                        @JonB said in qss and children objects:

                        Did you try

                        Hi
                        Same results and with

                        QWidget:hover > QPushButton { ...
                        

                        and with

                        QWidget#widget:hover > QPushButton#btn { ...
                        

                        :(

                        1 Reply Last reply
                        1

                        • Login

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