views:

79

answers:

4

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
+1. Or use addPixmap(), depending on whether that is more convenient.
Chris Cameron
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
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
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
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