user3842408
user3842408

Reputation: 89

Qt: Change the icon in a QListView

Is there a way to change the icon of an element in a QListView after it has been displayed?

I can't find a way to do a setData with the DecorationRole (the role used for the icon).

The model used is a custom QFileSystemModel, but the default implementation is only good for the EditRole so to change the name of the item.

I'm don't know how the the overridden setData can be done.

The goal is to change the icon when the mouse is over the item (through mouseMoveEvent)

Upvotes: 1

Views: 891

Answers (1)

You will need to subclass QListView and implement the behavior that changes the role of the displayed icon when the mouse hovers over the item.

Such a subclass could use an internal proxy model so that it wouldn't need to mess with the base view's painting. Simply inform the proxy that a given item's decoration role data has changed, and the base view will know what to do.

Upvotes: 1

Related Questions