简体   繁体   中英

PyQt4: How to change title of sub window when it is modified

class MdiChild(QtGui.QTextEdit):
    sequenceNumber = 1

    def __init__(self):
        super(MdiChild, self).__init__()

        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.isUntitled = True

    def newFile(self):
        self.isUntitled = True
        self.curFile = "document%d.txt" % MdiChild.sequenceNumber
        MdiChild.sequenceNumber += 1
        self.setWindowTitle(self.curFile + '[*]')

        self.document().contentsChanged.connect(self.documentWasModified)

    def documentWasModified(self):
        self.setWindowModified(self.document().isModified())

this code display the document1.txt as title of sub window when new sub window is created and keep increamenting. The title of sub window change from document1.txt to document1.txt.* when i change text in QTextedit and if i remove [] around * it display document1.txt.* when a new window is opened. so i want to know what is the working of [] in this code for document title and how * is append to document title. And please also tell the meaning of the following line:

self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

As mentioned in the docs

If you use the windowModified mechanism, the window title must contain a "[ ]" placeholder, which indicates where the ' ' should appear. Normally, it should appear right after the file name (eg, "document1.txt[*] - Text Editor"). If the windowModified property is false (the default), the placeholder is simply removed.

Now you second question about self.setAttribute(QtCore.Qt.WA_DeleteOnClose) WA_DeleteOnClose clears the memory of the closed document.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM