Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt QListWidget Item with Alternating Colors

I'm trying to get like a checkerboard pattern into a QListWidget. for example, have the first item in the list a dark grey background, and the second item in the list would have a light grey background and keep alternating like that as it goes down. Is there a simple way to accomplish this?

I know I can do it by creating a class, extending a QListWidget and then just set the styles in it each time the list updates but I'm looking for the simplest way possible. Any answers would be helpful.

like image 896
David Ludwig Avatar asked Dec 06 '22 02:12

David Ludwig


1 Answers

 listWidget->setAlternatingRowColors(true);

It's a built-in property of Qt.

If you use designer:

enter image description here

like image 123
Tay2510 Avatar answered Dec 09 '22 14:12

Tay2510