#include <QApplication>
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPushButton *button = new QPushButton("Quit");
QObject::connect(button, SIGNAL(clicked()),
&app, SLOT(quit()));
/*
QPalette pal = button->palette();
QColor clrBtn(255,0,0);
pal.setColor(QPalette::Button, clrBtn);//该句不起作用
pal.setColor(QPalette::ButtonText,clrBtn);
button->setPalette(pal);
*/
button->setStyleSheet("color:green;");
QString buttoncolor =button->styleSheet();//保存上一状态的stysheet
button->setStyleSheet(buttoncolor + "\nbackground:rgb(255,0,0);");
//QString buttoncolor =button->styleSheet();
//button->setStyleSheet(buttoncolor);
button->show();
return app.exec();
}