QScrollArea *scrollArea = new QScrollArea(parent); scrollArea->setBackgroundRole(QPalette::Window); QLinearGradient gradient(0, 0, 0, scrollArea->height()); gradient.setColorAt(0, QColor("#2C8EBB")); gradient.setColorAt(1, QColor("#1B587C")); scrollArea->viewport()->setBackground(QBrush(gradient));
QScrollArea *scrollArea = new QScrollArea(parent); scrollArea->setBackgroundRole(QPalette::Base); QPixmap pixmap(":/path/to/image.jpg"); QPalette palette; palette.setBrush(QPalette::Base, pixmap); scrollArea->viewport()->setPalette(palette);In this example, the QPalette::Base role is set as the background role, which is a generic role used to draw the background color of most widgets. Then, a QPixmap of an image is loaded and applied to the viewport by setting the palette of the viewport. The QScrollArea widget is part of the Qt Widgets module, which is part of the Qt C++ library.