Reputation: 153
I have a class that creates a QListView item, and the following functions that add items to the the list and also add icons to specific items in the list. Having a hard time figuring out how to remove an icon from a single item (or even all items) in the list.
self.list_view = ui_object.ListView(width=350, height=150) # This is just a custom QListView Class
self.model = QStandardItemModel(self.list_view)
self.list_view.setModel(self.model)
self.list_view.setEditTriggers(QAbstractItemView.NoEditTriggers)
@pyqtSlot(object)
def add_chargecode(self, matching_names):
for name in matching_names:
item = QStandardItem(name)
self.model.appendRow(item)
def set_as_default(self, chargecode):
chargecode_list = self.model.findItems(chargecode, Qt.MatchExactly)
for item in chargecode_list:
item.setData(QIcon(self.ctx.delete_icon['red']), Qt.DecorationRole)
def remove_icon(self, chargecode):
chargecode_list = self.model.findItems(chargecode, Qt.MatchExactly)
for item in chargecode_list:
item... # Help ? Remove Icons for These Items
Upvotes: 0
Views: 343
Reputation: 243897
You have to pass None as the value associated with the role Qt::DecorationRole
:
for item in chargecode_list:
item.setData(None, Qt.DecorationRole)
Upvotes: 1