I have a listwidget with items which have icons. When the item is selected both the text and the icon are highlighted. My problem is that when the icon is highlighted it just goes entirely black because I'm using only two colours. Is there a way to prevent the icon from being selected?
+1
A:
You can add additional images to the QIcon, depending on it's state:
QIcon icon(...);
icon.addFile("selected.png", size, QIcon::Selected);
See also the documentation of QIcon::addFile().
sth
2010-01-28 01:16:02
+1. Or use addPixmap(), depending on whether that is more convenient.
Chris Cameron
2010-01-28 01:19:41
Thanks but that didnt solve it, I set images for all modes and states and it still goes black when the item is selected because it still gets highlighted. I think I need a way to prevent the icon being highlighted at all and just have the text get highlighted.
Mark
2010-01-28 01:34:10
A:
Thanks but that didnt solve it, I set images for all modes and states and it still goes black when the item is selected because it still gets highlighted. I think I need a way to prevent the icon being highlighted at all and just have the text get highlighted.
Mark
2010-01-28 01:33:49
A:
Hey again,
Another possibility would be to reimplement QListWidgetItem... You could therefore have a bigger control on how things gets done during the process of selection and painting...
Of course, it's a lot more work...
Andy M
2010-01-28 09:44:31
A:
Best solution was to make your own qstyle which handled the painting of the backgrounds of listitem sub controls and draw the icons qrect as white
Mark
2010-02-01 04:08:04