What is the way to go to prevent duplicates in a QListView which uses QStandardItemModel as its model? Data is added with drag & drop, so I tried to override QStandardItemModel::dropMimeData, which seems kind of odd since I need to override QStandardItemModel::mimeData (and reimplement encodeData/decodeData) as well. This has to be easier!
Share
Well, I managed to solve this by overriding QListView::dataChanged, which checks if there is more than one item with the same data for Qt::DisplayRole in the model after dropping and deletes one of them if there is. It basically looks like that:
It’s by far not perfect (e.g. if you can drop more than one item at once) but it works for that simple use case.