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. Stylesheet inheritance with pseudo-states
Forum Updated to NodeBB v4.3 + New Features

Stylesheet inheritance with pseudo-states

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 210 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.
  • MegamouseM Offline
    MegamouseM Offline
    Megamouse
    wrote on last edited by Megamouse
    #1

    Hi,

    I have a stylesheet issue.
    Using this notation:

    #my_widget #my_label {
        color: black;
    }
    #my_widget:focus #my_label {
        color: white;
    }
    

    my_label is always using a white text color, even if my_widget is not focused.
    The focus itself works, tested with background color of my_widget.

    Is there any reason why this descendant usage doesn't work properly?

    Thanks,
    Megamouse

    MegamouseM 1 Reply Last reply
    0
    • MegamouseM Megamouse

      Hi,

      I have a stylesheet issue.
      Using this notation:

      #my_widget #my_label {
          color: black;
      }
      #my_widget:focus #my_label {
          color: white;
      }
      

      my_label is always using a white text color, even if my_widget is not focused.
      The focus itself works, tested with background color of my_widget.

      Is there any reason why this descendant usage doesn't work properly?

      Thanks,
      Megamouse

      MegamouseM Offline
      MegamouseM Offline
      Megamouse
      wrote on last edited by Megamouse
      #2

      It turns out the solution is to use the existing QProperty declarations in the QWidget header:

      #my_widget #my_label {
          color: black;
      }
      
      // This does not work
      // #my_widget:focus #my_label {
      //     color: white;
      // }
      
      // This works
      #my_widget[focus="true"] #my_label {
          color: white;
      }
      

      Sadly, to make this work, you still need to check the focus events of your parent widget and do:

      my_label->style()->unpolish(my_label);
      my_label->style()->polish(my_label);
      

      Also, the hover state doesn't seem to be represented as QProperty, so I'll have to add that property manually and query the QHoverEvents

      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