ability to apply stylesheet to individual items in QComboBox or QListView
Unsolved
Brainstorm
-
I was surprised and disappointed to discover that one cannot apply stylesheets to individual items in a QComboBox or QListView. One can separately set the background color, foreground (text) color, and the font size, but this is cumbersome and does not support the wide range of effects that is possible with stylesheets. Has anyone thought about adding this capability? Why does this ugly dichotomy exist?
Dr. Phillip M. Feldman
http://phillipmfeldman.org -
Hi, while I think you're correct about QComboBox, for QListView I think you can apply individual stylesheets to it. If you can use a QListWidget instead I have an example:
for (int i = 0; (i < 10); ++i) ui->listWidget->addItem(new QListWidgetItem("")); QLabel* l1 = new QLabel("Item1",this); l1->setStyleSheet("* { color: #FF0000; }"); ui->listWidget->setItemWidget(ui->listWidget->item(0),l1); QLabel* l2 = new QLabel("Item2",this); l2->setStyleSheet("* { color: #00FF00; }"); ui->listWidget->setItemWidget(ui->listWidget->item(1),l2);