开发者

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开发者_Python百科. 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)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜