QListWidgetItem* item = new QListWidgetItem(); QColor color(Qt::red); QBrush brush(color); item->setBackground(brush); item->setData(Qt::BackgroundRole, brush);
QListWidgetItem* item = new QListWidgetItem("Hello World"); QColor color(Qt::green); QBrush brush(color); item->setTextColor(brush.color()); item->setData(Qt::ForegroundRole, brush);In this example, we create a new QListWidgetItem with the text "Hello World". Then, we set its text color to green and setData function sets the foreground role with the created brush. Package library: Qt