第一种:
ui->pushButton->setAutoFillBackground(true);
QColor color = QColorDialog::getColor();
int red = color.red();
int green = color.green();
int blue = color.blue();
QString string = QString("background-color:rgb(%1,%2,%3)").arg(red).arg(green).arg(blue);
ui->pushButton->setStyleSheet(string);
第二种:
//弹出颜色选择框
QColor color = QColorDialog::getColor(Qt::white, this);
QPalette pal = ui->pushButton->palette();
pal.setColor(QPalette::Button,color);
ui->pushButton->setPalette(pal);
ui->pushButton->setAutoFillBackground(true);
ui->pushButton->setFlat(true);