PDA

View Full Version : palette setColor QPushButton



TheKedge
2nd November 2006, 12:33
I'm sorry about this, I know there are lots of threads changing the colours of widgets, but it's just not working for my QPushButton.

I do this first
buttonH1->setAutoFillBackground (true);
and then I've tried this
buttonH1->setPalette(Qt::green);
and this
QPalette palette;
palette.setColor(QPalette::Button, Qt::green);
buttonH1->setPalette(palette);
and this
palette.setColor(buttonH1->backgroundRole(), Qt::green);
buttonH1->setPalette(palette);
I get a green 'lining' around the button and/or green text but the button itself remains grey.

I've also tried setting all the palette to green, as below. I don't get a green button.

//palette.setColor(QPalette::Window, Qt::green);
//palette.setColor(QPalette::Background, Qt::green);
//palette.setColor(QPalette::WindowText, Qt::green);
//palette.setColor(QPalette::Foreground, Qt::green);
//palette.setColor(QPalette::Base, Qt::green);
//palette.setColor(QPalette::AlternateBase, Qt::green);
//palette.setColor(QPalette::Text, Qt::green);
palette.setColor(QPalette::Button, Qt::green);
//palette.setColor(QPalette::ButtonText, Qt::green);
//palette.setColor(QPalette::BrightText, Qt::green);


Could somebody please tell me what I need to do?
thanks
K

jpn
2nd November 2006, 14:18
Are you using WinXP? It's not possible with QWindowsXPStyle (it uses native WinXP theming engine for drawing controls such buttons). You could try to set the style of the button explicitly to something else like:



QStyle* style = new QPlastiqueStyle; // or QWindowsStyle
buttonH1->setStyle(style);

TheKedge
2nd November 2006, 14:41
brilliant, thanks! What other widgets are affected by that? Is there a list anywhere? Documentation?

thanks,
K

wysota
3rd November 2006, 11:14
Furthermore, if you are using Qt4.2, you can achieve the same quickly by setting a stylesheet for your button. The stylesheet string should contain something like: "background: green;"


brilliant, thanks! What other widgets are affected by that? Is there a list anywhere? Documentation?

WindowsXP style and Mac Aqua styles are affected in general.That's the famous "red pushbutton issue". That's why Trolltech introduced stylesheets for their widgets in Qt 4.2. I suggest you take a look at its documentation (http://doc.trolltech.com/4.2/stylesheets.html).