1

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)

user3842408
  • 89
  • 1
  • 10
  • Subclass `QFileSystemModel` and pad `DecorationRole` to `setData`? But then you need to know where to set the icon to so that the view can access it via model's`data()`. – user3528438 Aug 03 '15 at 20:18

1 Answers1

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.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • I don't understand what "changing the role of the displayed icon" means or implies. – user3842408 Aug 03 '15 at 20:45
  • @user3842408 The source model provides two icons, default under the DecorationRole, and a hover one under a custom role. The proxy redirects requests for the DecorationRole data to either the same role, or the custom hover role, depending on directions from the subclassed view. – Kuba hasn't forgotten Monica Aug 03 '15 at 21:17