views:

127

answers:

1

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)
window = QtGui.QMainWindow()
edit = MyTextEdit()
window.setCentralWidget(edit)
window.setWindowTitle("None [*]")
window.show()
app.exec_()
+1  A: 

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)

Jesse Aldridge