0

I'm enumerating valuesUnique object which is QtGui.QStandardItemModel object with:

for actionNumber, actionName in enumerate(sorted(list(set(valuesUnique)))):
    action = QtWidgets.QAction(actionName, self)
    self.signalMapper.setMapping(action, actionNumber)
    action.triggered.connect(self.signalMapper.map)
    self.menuValues.addAction(action)

Where valuesUnique is generated from model:

valuesUnique = [self.model.item(row, self.logicalIndex)
                        for row in range(self.model.rowCount())
                        ]

And model is created from

class PandasTableModel(QtGui.QStandardItemModel):
...

from pandas DataFrame.

Error i get:

unhashable type: 'QStandardItem'

How can I fix enumeration part?

Hrvoje
  • 13,566
  • 7
  • 90
  • 104
  • 1
    The problem is with creating a `set` from a collection of `QStandardItem`s. Besides that, `QAction` expects a string as an input parameter, not a `QStandardItem` when initializing an instance. Did you perhaps mean `valuesUnique = [self.model.item(row, self.logicalIndex).text() for row in range(self.model.rowCount())]`? – Heike Aug 28 '20 at 11:39
  • @Heike . Works! :) Great, thank you! Can you formulate that in answer so I can accept it? – Hrvoje Aug 28 '20 at 14:41
  • https://stackoverflow.com/questions/47749631/qstandarditem-missing-hash-method is not answer to this question. Answer is in the comment of @Heike – Hrvoje Aug 28 '20 at 23:19

0 Answers0