Qt,如何向父窗口小部件发出信号?

时间:2014-06-12 19:24:00

标签: python qt5 pyside qitemdelegate

您好我创建了一个小部件,可以在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条目

0 个答案:

没有答案