QPushButton background color not working
-
Hi,
I'm trying to color the background of a QPushButton, but it does not work.
@
QPushButton* blau = new QPushButton("Blau", &F);
QPalette pal_blau = blau->palette();
pal_blau.setColor(QPalette::Button, QColor(0,0,255));
blau->setPalette(pal_blau);
blau->setAutoFillBackground(true);
@Using gnome 2.28.2 on Centos 6.3
It seems that there is a little border in blue around the button, but the button background has no color changed.
Any suggestions?
Thank you
-
Shouldn't you try it using the stylesheet? Much easier and can be done in designer.
greetz -
I would like to do it using QPalette
-
Change line 3 with :
@
pal_blau.setColor(QPalette::Background, QColor(0,0,255)
@ -
It does not work either :/
-
Well, I think for settings buttons background color, style sheet is the way to go ... (I think Qt use OS theme effect, hence some palette modifications don't have any effect)
-
The documentation on QPalette states:
[quote]
Warning: Some styles do not use the palette for all drawing, for instance, if they make use of native theme engines. This is the case for both the Windows XP, Windows Vista, and the Mac OS X styles.[/quote]So, basically, most rendering on popular, modern OS's bypasses the palette completely.
Using style sheets really is the only relyable way.
-
Maybe this helps you out: "How_to_Change_the_Background_Color_of_QWidget":http://qt-project.org/wiki/How_to_Change_the_Background_Color_of_QWidget