PDA

View Full Version : Change ONLY the background color of a QFrame, not everything in it.



emp1953
8th January 2020, 20:58
I have a QFrame that I want to change the background color.

I do so using the following:

my_qframe->setStyleSheet("background-color:yellow;");

Which works -- to a point

I have several buttons in that frame. I do not want their colors changed, but they do change.

Is there a way around this?

Thank You

emp1953

ChrisW67
9th January 2020, 08:12
I have a QFrame that I want to change the background color.
...

Perhaps:


my_qframe->setStyleSheet("QFrame { background-color:yellow; }");

emp1953
9th January 2020, 17:46
Perhaps:


my_qframe->setStyleSheet("QFrame { background-color:yellow; }");


Thank you this worked perfectly. How do I mark this solved?

Added after 13 minutes:

chrisw67, It seems to work only if buttons are in the qframe. Some of the frames have listwidgets and they turn green and stay that way. Do I have to take an additional step and use a stylesheet to turn them back?

ChrisW67
10th January 2020, 08:11
The list widget will not be going green because of the QFrame style above, which only mentions yellow. The QListWidget class inherits from QFrame so it can be affected by a style selector "QFrame". You can change that behaviour by changing the selector:


my_qframe->setStyleSheet(".QFrame { background-color:yellow; }");

See Qt5 Style Sheet Syntax (https://doc.qt.io/qt-5/stylesheet-syntax.html) esp. under Selector Types heading.

Where else are you applying style sheets? They cascade down to contained widgets, so it may be a parent widget with a style sheet that is driving this.