QColor blue(0, 0, 255); widget->setStyleSheet(QString("background-color: %1").arg(blue.name()));
QLinearGradient gradient(0, 0, 0, height); gradient.setColorAt(0, QColor(0, 0, 255)); gradient.setColorAt(1, QColor(255, 255, 255)); QBrush brush(gradient); painter->setBrush(brush);This code creates a QLinearGradient object that starts at the top of the graphical context and ends at the bottom. The color of the gradient is set to transition from blue (RGB value of 0, 0, 255) at the start to white (RGB value of 255, 255, 255) at the end. The gradient is then used to create a QBrush object, which is passed to a QPainter object to set the brush used for drawing. Package library: Qt