QLabel* label = new QLabel("Hello World!", this); QPalette palette = label->palette(); palette.setColor(QPalette::WindowText, Qt::blue); label->setPalette(palette);
QWidget* widget = new QWidget(this); QPalette palette = widget->palette(); palette.setColor(QPalette::Background, Qt::green); widget->setAutoFillBackground(true); widget->setPalette(palette);In this example, we create a QWidget and set its palette to the default palette using the `palette` method. We then set the background color to green using the `setColor` method and `QPalette::Background` as the first argument. We enable auto-fill background using the `setAutoFillBackground` method and set the palette to the modified palette using the `setPalette` method. Package/Library: Qt Core and Qt Widgets.