View Full Version : change text color for handmade Widget in QListWidget

31st October 2014, 18:06
Hello all. I need your advice. I have a QListWidget, and QListWidgetItem
QListWidgetItem *item = new QListWidgetItem;

and I add my handmade navigation widget to item
ui.listWidget->setItemWidget(itm, navWidget);

Now I change background for selected item
background: gray;
color: yellow;
and I want my navigation widget changed text color when item, to which it belongs, is selected. If another item selected, previous item navigation widget return his previous color text. How I can release this task?

1st November 2014, 03:23
Give your nav widget a function to set it active (or not) and change its properties/paint it accordingly. Then capture when the current item of the list widget changes and set the previous widget (if there is one) inactive and the new widget (if there is one) active.


1st November 2014, 09:56
The task is solved!

3rd November 2014, 07:15
Had you also tried by setting stylesheet for -
QListWidget:item:selected:!active ?

3rd November 2014, 19:35
Indeed. That might be easier (if a tiny bit slower). You can tell I don't do stylesheets.

4th November 2014, 11:04
I don't think stylesheets are going to work if a widget is put in a cell. The stylesheet is applied to the item and not to the widget that replaces it. I'd be very surprised if it worked.