setEditorData
和
setModelData
-1
对于空列表。
以下是委托类的外观:
class DelegateLEdit(QStyledItemDelegate):
def createEditor(self, parent, option, index):
line_edit = QLineEdit(parent)
return line_edit
def setEditorData(self, editor, index):
editor.setText(index.data())
def setModelData(self, editor, model, index):
model.setData(index, editor.text())
class DelegateLWidget(QStyledItemDelegate):
def createEditor(self, parent, option, index):
list_widget = QListWidget(parent)
list_widget.setSelectionMode(QAbstractItemView.ExtendedSelection)
list_widget.addItems('One Two Three Four'.split()) # or whatever
return list_widget
def setEditorData(self, editor, index):
for line in index.data().splitlines():
for item in editor.findItems(line, Qt.MatchExactly):
item.setSelected(True)
def setModelData(self, editor, model, index):
text = '\n'.join(item.text() for item in editor.selectedItems())
model.setData(index, text)