Selected QListWidgetItem without changing text color

I have a qListWidget with some elements that have different text colors. I want to change the background color of the selected item without touching the color of the text. I tried using StyleSheet, but then all the selected elements have the same colors. Can I select an item without changing the color of the text?

-1
source share
1 answer

Try to use item->setData(Qt::BackgroundRole, QBrush(color));.

0
source

All Articles