python pyqt5 different item color in same qlist code example
Example: python pyqt5 different item color in same qlist
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
colors = [ '#7fc97f', '#beaed4', '#fdc086', '#ffff99', '#386cb0', '#f0027f', '#bf5b17', '#666666']
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
w = QListWidget()
for n in range(8):
i = QListWidgetItem('%s' % n)
i.setBackground( QColor(colors[n]) )
w.addItem(i)
self.setCentralWidget(w)
self.show()
app = QApplication([])
w = MainWindow()
app.exec_()