closeEditor只接受2个参数(给定2个)

时间:2013-07-10 09:19:55

标签: pyqt pyside qtablewidget qlineedit qstyleditemdelegate

有谁知道我为什么会收到以下错误:

TypeError: closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint) only accepts 2 arguments, 2 given!

我正在使用QStyledItemDelegate,因此我可以使用自己的QLineEdit更好地控制表(QTableWidget())。当我离开使用自定义编辑器控制的表格单元格的焦点时,会发生错误。

以下代码基于PySide stardelegate.py example

class EditDelegate(QStyledItemDelegate):
    def __init__(self, parent=None):
            super(EditDelegate, self).__init__(parent)
    def createEditor(self, parent, option, index):
            result = index.column()
            if result==0:
                    editor = TheEditor(parent)
                    editor.editingFinished.connect(self.commitAndCloseEditor)
                    return editor
            else:
                    return QStyledItemDelegate.createEditor(self, parent, option, index)
    def commitAndCloseEditor(self):
            editor = self.sender()
            self.commitData.emit(editor)
            self.closeEditor.emit(editor)
class TheEditor(QLineEdit):
    editingFinished = Signal()
    def __init__(self, parent=None):
            super(TheEditor, self).__init__(parent)
            self.setAutoFillBackground(True)
            self.setValidator(QIntValidator(0,999999999, self))
    def focusOutEvent(self, event):
            self.editingFinished.emit()

1 个答案:

答案 0 :(得分:1)

因为,你必须发出信号closeEditor,说出所需的提示:EditNextItem,EditPreviousItem o NoHint。

self.closeEditor.emit(editor, QAbstractItemDelegate.NoHint)

HTH