当前位置: 动力学知识库 > 问答 > 编程问答 >

python - 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)

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)

分享给朋友:
您可能感兴趣的文章:
随机阅读: