I'm reading up on how to make my QAbstractTableModel editable, and it looks pretty straightforward.
But how do I set up an editable cell to use a QCompleter? I take it somehow I have to tell the QTableView to use a QLineEdit widget? How can I do this?
edit: hmm, I guess it has something with QTableView.setItemDelegateForColumn() but I don't know anything about delegates or how to use them.
edit: I tried RobbieE's solution, got something that sort of works but it gets the geometry of the popup combo box wrong and crashes Python when I press Enter.
class CompleterDelegate(QtGui.QStyledItemDelegate):
def __init__(self, parent=None, completerSetupFunction=None):
super(CompleterDelegate, self).__init__(parent)
self._completerSetupFunction = completerSetupFunction
def createEditor(self, parent, option, index):
return QtGui.QLineEdit(parent)
def setEditorData(self, editor, index):
super(CompleterDelegate, self).setEditorData(editor, index)
self._completerSetupFunction(editor, index)
My _completerSetupFunction looks something like this:
def setupFunc(editor, index):
completer = MyCompleter(editor)
completer.setCompletionColumn(0)
completer.setCompletionRole(QtCore.Qt.DisplayRole)
completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive)
editor.setCompleter(completer)
completer.setModel(myAbstractItemModel)