Qt: how to set the background color of QPushButton to System-color?
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
Have you tried using setBackgroundRole
for the button? Maybe your button has QPalette::NoRole
and therefore inherits its role from its parent.
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.
精彩评论