Hover over widget should set child widget color style.
-
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?
-
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 -
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.
-
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.
-
[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?