문제

I have a custom widget which inherits from QWidget and contains some labels in its layout. I would like to change the background color of the widget and the labels in the widget (this is, everything!) every time I put the mouse over it.

When using *:hover { background: red; } in my custom widget, I only get the contents red when moving the mouse over the labels, but not outside them, between labels, etc. I don't understand this behavior taking into account that I put the StyleSheet in the parent widget.

Any ideas? Many thanks,

도움이 되었습니까?

해결책 2

Finally I solved the problem creating a QFrame inside the main QWidget and setting the StyleSheet of that QFrame.

다른 팁

You can set the parent's stylesheet which will cascade to children like this:

parent->setStyleSheet("* {background: red}");

For hovering only:

parent->setStyleSheet("*:hover {background: red}");

Check out https://qt-project.org/doc/qt-5.1/qtwidgets/stylesheet-syntax.html

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top