【问题标题】:PyQt QTextEdit: Detect change EventPyQt QTextEdit:检测更改事件
【发布时间】:2013-07-26 19:01:28
【问题描述】:

我在 PyQT QTextEdit 中覆盖一些事件,例如:

class myTextEditor(QTextEdit):
    def keyPressEvent(self,e):
                print 'key pressed'
        return super(myTextEditor, self).keyPressEvent(e)

但是,changeEventdocumented here,似乎不起作用。这是我的代码

def changeEvent(self,e):
    print 'change'
    return super(myTextEditor, self).changeEvent(e)

没有错误,但未处理该事件。

任何想法如何在 PyQt 中使用 changeEvent(文本更改时)进行 QTextEdit?

【问题讨论】:

    标签: python qt events pyqt pyqt4


    【解决方案1】:

    changeEvent 与更改文本编辑的内容无关。它仅解决一般的 QWidget 状态更改。请参阅this page 以获取与此方法相关的事件列表。

    您应该连接到QTextEdit::textChanged() 信号以跟踪文本更改。

    【讨论】:

    • 这是我尝试过的:self.textChanged.triggered.connect(self.changeText)。我得到以下信息:pyqtsignal must be bound to a Qobject, not mytexteditor
    • 尝试删除.triggered。它绝对不应该在那里。
    • 可能是self 不是正确的QObject。请参阅this answer 中的示例。
    • 确实在连接之前我忘了做super(myTextEditor, self).__init__(parent) b。谢谢!!
    • 有效的是 self.textEdit.textChanged.connect(self.doSomething)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-26
    • 2012-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-30
    • 1970-01-01
    相关资源
    最近更新 更多