QPalette pal = button->palette(); pal.setColor(QPalette::Button, QColor(Qt::red)); pal.setColor(QPalette::ButtonText, QColor(Qt::white)); button->setPalette(pal);
QPalette pal = mainWindow->palette(); pal.setBrush(QPalette::Background, QBrush(QColor(255, 255, 255))); mainWindow->setPalette(pal);In this example, we are creating a new palette object and setting the background color of the QMainWindow to white by setting the background brush of the palette. The QPalette class is part of the QtGUI library, which is included in the QtGui module of the Qt library.