PDA

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



Holiday
31st October 2014, 19:06
Hello all. I need your advice. I have a QListWidget, and QListWidgetItem
QListWidgetItem *item = new QListWidgetItem;
item->setSizeHint(size);
ui.listWidget->addItem(item);

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

Now I change background for selected item
QListWidget:item:selected:active
{
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?

ChrisW67
1st November 2014, 04: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.

QListWidget::currentItemChanged()

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

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

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

wysota
4th November 2014, 12: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.