こんにちは、私はそれを使用するウィジェットを作成しました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())
ユーザーが の値を変更するとComboDelegate
、そのウィジェットは別のセルの値を更新します。このセルは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 エントリは更新されません