1.如果派生类的父类自定义了paintEvent函数的使用。QPalette设置无效有可能是被paintEvent函数的自定义内容覆盖。
2.或者是未设置这行代码this->setAutoFillBackground(true);
void MainWindow::setbackground(QString fileName)
{
this->setAutoFillBackground(true);
QPalette palette;
QPixmap pixmap(":/image/12.jpg");
pixmap =pixmap.scaled(this->size());
palette.setBrush(backgroundRole(),QBrush(pixmap));
setPalette(palette);
}