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. Hover over widget should set child widget color style.
QtWS25 Last Chance

Hover over widget should set child widget color style.

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 5.2k 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.
  • W Offline
    W Offline
    Woomla
    wrote on last edited by
    #1

    I have a QWidget #myWidget that contains several QLabels. I want the text color of the labels to be red:
    @#myWidget {
    color:red;
    }@

    That doesn't work, I must tell the style to set the embedded QWidgets:
    @#myWidget QWidget {
    color:red;
    }@

    When I hover my mouse over #myWidget, I want the text color of all labels to be blue:
    @#myWidget:hover QWidget{
    color:blue;
    }@

    But what happens is that all labels are always blue. So what can/should I do?

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hi,
      I also experienced that problem. The reason for the colour change is that the parent controls the stylesheet of the children. So when the stylesheet of the parent changed, it changes for the children accordingly. I fixed it the "not so nice" way and set the stylesheets for the children manually. Not great, but workable. There is also an option of setting the stylesheet for certain objects only like:
      @
      QString strStyle("QLabel{border-image: url(...)}");
      ui->labelTitle->setStyleSheet(strStyle);@
      Then only QLabels should have the border image changed, or if you need only the color.
      Maybe this will give a good start in finding the proper answer.
      Greetz

      Greetz, Jeroen

      1 Reply Last reply
      0
      • W Offline
        W Offline
        Woomla
        wrote on last edited by
        #3

        Thanks for your answer.

        I don't think the parent is changed at this moment. #myWidget color is red, #myWidget QWidget color is red. Only #myWidget:hover QWidget color is blue. But all labels of all #myWidgets are blue!

        That said, I have multiple #myWidgets! That's because it's a user created widget.

        1 Reply Last reply
        0
        • W Offline
          W Offline
          Woomla
          wrote on last edited by
          #4

          Actually it's not #myWidget but #MyWidget in the css. MyWidget is derived from QWidget. It's necessary to put the '#' in front of MyWidget in the css otherwise it won't work. For QWidget i.e. this is not required?

          Thus:
          @#MyWidget:hover {
          background: #555;
          }@

          will set the background when the mouse is over MyWidget, but
          @MyWidget:hover {
          background: #555;
          }@

          will do nothing.

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            [quote author="Woomla" date="1369993231"]But what happens is that all labels are always blue. So what can/should I do?[/quote]
            What do you mean with "always"? Even if your cursor isn't hovering your application window?

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

            1 Reply Last reply
            0
            • W Offline
              W Offline
              Woomla
              wrote on last edited by
              #6

              Correct, even when my cursor is not hovering a MyWidget / my application window. The color is always blue.

              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