1
votes

I have a QPushbutton on a parent-Widget. I want now to give the parent-Widget a new Background (color, image eg.) this works fine (using QPalette). However, as I am using Unix, the color from the parent-Window is propagated to the Button. Like the button has transparent background. This is fine for some cases, but sometimes I just want the parent-Widget's background to change an not the children. So that the Buttons will keep their original "system"appearance. How to achieve this? I tried a lot...but nothing gave me the desired result. Any ideas on how to achieve that?

Thx

2

2 Answers

0
votes

Have you tried using setBackgroundRole for the button? Maybe your button has QPalette::NoRole and therefore inherits its role from its parent.

0
votes

if your Button seems to inherit the background from the MainWindow, try setting stylesheet in this format.

this->setStyleSheet("MainWindow{background-color:red}");

Now, the background will not be inherited by your button.