Question

I was wondering if it was possible to highlight multiple rows in a QListWidget (not setSelectedRow or select multiple rows)...And if so, how would i go about doing that??

Was it helpful?

Solution

There are many ways to highlight the items in a listWidget. You can set the background color, foreground color or completely change the font of the items to be highlighted.

Set the foreground:

for item in listWidget.selectedItems():
    item.setForeground(QBrush(Qt.green, Qt.SolidPattern))

Set the background:

for item in listWidget.selectedItems():
    item.setBackground(QBrush(Qt.yellow, Qt.SolidPattern))

Or change the font of the items:

font = QFont('', -1, QFont.Bold, True)
for item in listWidget.selectedItems():
    item.setFont(font)

Empty string to QFont means default font family, -1 means default font size, finally made the font bold and made it italic by setting the last parameter to True. If you don't want bold font, pass -1 instead of QFont.Bold

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top