Is it possible to highlight (not select) multiple rows in QListWidget?? (Python/PyQt)

StackOverflow https://stackoverflow.com/questions/23141429

  •  05-07-2023
  •  | 
  •  

Frage

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??

War es hilfreich?

Lösung

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top