QListWidgetItem *item = new QListWidgetItem("Item Text"); QBrush brush(Qt::blue); item->setBackground(brush);
QListWidgetItem *item = new QListWidgetItem("Item Text"); QLinearGradient gradient(0, 0, 0, item->sizeHint().height()); gradient.setColorAt(0, Qt::red); gradient.setColorAt(1, Qt::yellow); QBrush brush(gradient); item->setBackground(brush);In both examples, we create a new QListWidgetItem object and set its background color using the setBackground function with a QBrush object representing the desired color. The QListWidgetItem class is part of the Qt core library.