mr_js
mr_js

Reputation: 1029

Correct way to use the signal closeEditor in QStyledItemDelegate?

I am overriding the QStyledItemDelegate class and reimplementing the eventFilter function so I can customize the editor behavior when a Tab press is detected. However, the following is not working. What is the correct way to invoke the closeEditor signal?

class CustomDelegate(QStyledItemDelegate):
    def __init__(self, parent=None):
        super(CustomDelegate, self).__init__(parent)

    def eventFilter(self, editor, event):
        if (event.type() == QEvent.KeyPress and
            event.key() == Qt.Key_Tab):
            print "Tab captured in editor"
            self.commitData.emit(editor) #This is working
            self.closeEditor.emit(editor) #This does not seem to do anything??
            return True
        return QStyledItemDelegate.eventFilter(self,editor,event)

Upvotes: 1

Views: 2224

Answers (1)

c00kiemonster
c00kiemonster

Reputation: 23361

This is an old question, but I just ran into the same issue and found this question.

I solved it by changing the

self.closeEditor.emit(editor)

line to

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

The commitData call will setModelData. If you don't call closeEditor, setModelData will be called again as the editor itself will close.

Upvotes: 4

Related Questions