QPalette palette; palette.setColor(QPalette::Window, Qt::red); QWidget *widget = new QWidget; widget->setPalette(palette);
QPalette palette; palette.setColor(QPalette::Text, Qt::blue); QTextEdit *textEdit = new QTextEdit; textEdit->setPalette(palette);
QPalette palette; palette.setColor(QPalette::WindowText, Qt::green); QLabel *label = new QLabel; label->setPalette(palette); label->setText("This is a green label!");This example sets the text color of a QLabel widget to green using the QPalette class. Package/library: Qt In conclusion, QPalette is a useful tool in Qt framework for setting and modifying color palettes of widgets in a GUI application using C++.