您好我创建了一个小部件,可以在QTableWidget
这个Widget是一个简单的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())
当用户更改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
时,父窗口小部件self.Table
没有收到信号,知道单元格已更改,因此它不会更新xml条目