Question

Does anyone know why I am getting the follow error:

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

I am using a QStyledItemDelegate so that I have more control over a table (QTableWidget()) using my own QLineEdit. The error occurs when I have left the focus of a table cell that is controlled with the custom editor.

The below code is based off the 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()
Was it helpful?

Solution

Because, you must emit the signal closeEditor saying the hint desired: EditNextItem, EditPreviousItem o NoHint.

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

HTH

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top