Search code examples
qtstylesheetqtstylesheets

How to set color of child QLabels while hover parent QFrame with QSS?


I'm trying to set the hover state color of 2 labels inside a QFrame with a stylesheet, but the frame takes the hover states regardless if there is an actual hover:

See screenshot: enter image description here

I've got a QFrame with QLabels. I set the default colors to green and purple. While i hover the QFrame, the color of both labels should go red.

The exact same CSS does work with html, but i can't seem to get it to work with the QT stylesheets.

div{background-color:black; width:200px; height:100px;}

#label1{color: green;}
#label2{color: purple;}

div:hover #label1 {color: red;}
div:hover #label2 {color:red;}

Solution

  • You could not do it with QLabel. It's limitation of QSS. Try to use QToolButton instead of QLabel (and customize QToolButton to look like QLabel).

    Possible you shuld use QToolButton instead of QFrame too.