嗨,我已经创建了一个小部件来使用它QTableWidget
这个小部件是一个简单的QComboBox
class ComboDelegate(QtGui.QItemDelegate):
"""
A delegate that places a fully functioning QComboBox in every
cell of the column to which it's applied
"""
def __init__(self, parent, options):
QtGui.QItemDelegate.__init__(self, parent)
self.options = options
self.parent = parent
def createEditor(self, parent, option, index):
combo = QtGui.QComboBox(parent)
combo.addItems(self.options)
self.connect(combo, QtCore.SIGNAL("currentIndexChanged(int)"), self, QtCore.SLOT("currentIndexChanged()"))
return combo
def setEditorData(self, editor, index):
editor.blockSignals(True)
editor.setCurrentIndex(editor.currentIndex())
editor.blockSignals(False)
def setModelData(self, editor, model, index):
self.parent.item(self.parent.currentRow(), 4).setText("%s Byte" % editor.currentIndex())
model.setData(index, editor.itemText(editor.currentIndex()))
#@QtCore.pyqtSlot()
def currentIndexChanged(self):
pass
self.commitData.emit(self.sender())
当用户更改 的 Value 时ComboDelegate
,该 Widget 会更新另一个单元格的值,该单元格是Size cell
self.parent.item(self.parent.currentRow(), 4).setText("%s Byte" % editor.currentIndex() # Size cell
在我的MainWindow
班级中,当单元格更改时,我分配了一个插槽
self.Table.cellChanged.connect(lambda: self.change_xml_entry(self.Table))
change_xml_entry
更新单元格时应该更新 xml 条目!当单元格直接从用户手动更新时它工作正常,但是当我的ComboDelegate
类更新时Size cell
,父 Widgetself.Table
没有收到知道单元格已更改的信号,因此它不会更新 xml 条目