版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gang950502/article/details/74990459
#include <QPalette>
#include <QColor>
void MyForm::set_form_color(){
this->setAutoFillBackground(true);
QPalette pale = this->palette();
QColor BKG_COL(0,0,0);
pale.setColor(this->backgroundRole(),BKG_COL);//正确写法1
//pale.setColor(this->backgroundRole(),Qt::blue);//正确写法1
//pale.setColor(QPalette::Window,Qt::darkRed);//这种写法没有效果
this->setPalette(pale);
}