开发者

PyQt: Trouble with asterisk on modification in QPlainTextEdit

I'm having a problem with a QPlainTextEdit. I want the "contents have been modified" asterisk to appear in the title bar whenever the contents have been modified.

In the example below, type a few letters. The asterisk appears as it should. Hit Ctrl+S, the asterisk disappears as it should. But then if you type a few more letters... why doesn't the asterisk appear again?

import os, sys

from PyQt4 import QtGui, QtCore

class MyTextEdit(QtGui.QPlainTextEdit):  
    def __init__(self):
        QtGui.QPlainTextEdit.__init__(self)     

        save_seq = QtGui.QKeySequence.Save
        self.save_shortcut = QtGui.QShortcut(save_seq, self, self.save)

        QtCore.QObject.connect(self, 
                               QtCore.SIGNAL("modificationChanged(bool)"),
                               self.on_change)

    def on_change(self, is_modified):
        print "on_change"
        window.setWindowModified(is_modified)

    def save(self):
        window.setWindowModified(False)
#


app = QtGui.QApplication(sys.argv)
开发者_JS百科window = QtGui.QMainWindow()
edit = MyTextEdit()
window.setCentralWidget(edit)
window.setWindowTitle("None [*]")
window.show()
app.exec_()


Never mind, figured it out. The problem was that in the save method I should've been calling self.document().setModified(False) instead of window.setWindowModified(False)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜