PDA

View Full Version : QPushButton BackColor



axisdj
21st September 2010, 18:15
I would like to change a backcolor theme of a QPushButton being Pressed. I am using QT Creator 2 and Windows 7. Here is the code. I tried using the StyleSheet option and it works fine, but in this case I will have a color dialog that will return the color that the button will need to change to. I would like the color not be solid, but gradient like it is by default but with a different themeColor.


QPushButton *button = this->findChild<QPushButton *>(text);
if ( button->text() != "Pressed")
{
button->setText("Pressed");

QColorDialog *myColorDialog;
QColor theColorPicked;
QPalette thePal;

theColorPicked = myColorDialog->getColor(QColor(0,0,0));
thePal.setColor(button->backgroundRole(),theColorPicked);
button->setPalette(thePal);

wysota
21st September 2010, 18:45
Windows7 cannot render a button with a different colour so you will lose your native decoration anyway and the only way you can do it with Windows7 style is through stylesheets.