1

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

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

我正在使用 QStyledItemDelegate,以便使用我自己的 QLineEdit 对表 (QTableWidget()) 进行更多控制。当我离开由自定义编辑器控制的表格单元格的焦点时,会发生错误。

以下代码基于PySide stardelegate.py 示例

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()
4

1 回答 1

1

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

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

高温高压

于 2013-07-10T18:44:01.290 回答