QWidget *widget = new QWidget(); QPalette palette = widget->palette(); palette.setColor(QPalette::Background, Qt::red); widget->setAutoFillBackground(true); widget->setPalette(palette);
QPainter painter(this); painter.fillRect(rect(), Qt::white);
QGraphicsScene *scene = new QGraphicsScene(); scene->setBackgroundBrush(Qt::white);In this example, we create a new QGraphicsScene and set its background brush to white using the setBackgroundBrush method. This will cause the background of the scene to be painted with the specified color. Package library: Qt GraphicsView