#includeint main() { // Create a QColor object representing the color green QColor green(0, 255, 0); return 0; }
#includeThis example sets the background color of a QWidget (a graphical control element) to green. It first sets the auto fill background property to true, which causes the widget to automatically fill its background with the color specified in its palette. It then creates a QPalette object from the widget's current palette, and sets the background color to green by calling the setColor() method with the background role and a QColor object with the values (0, 255, 0). Finally, it sets the updated palette back to the widget. The package library used for working with QColor is the Qt library.int main() { // Set the background color of a QWidget to green QWidget widget; widget.setAutoFillBackground(true); QPalette palette = widget.palette(); palette.setColor(widget.backgroundRole(), QColor(0, 255, 0)); widget.setPalette(palette); return 0; }