QListWidgetItem* item = new QListWidgetItem("Item 1"); item->setBackgroundColor(Qt::red);
QColor color; for(int i=0; iIn the above example, we are looping through all the items in a QListWidget and setting the background color of each item based on whether its index is even or odd. Package library: Qt Core Library.count(); i++){ QListWidgetItem* item = listWidget->item(i); if(i%2 == 0){ color = Qt::red; } else{ color = Qt::green; } item->setBackgroundColor(color); }