The following is the implementation of a simple text editor that is extended from the previous examples in its building version. This code contains some new features, such as QFontDialog
, QFileDialog
, and so on, which are discussed in Chapter 5, Dialogs and Widgets. Otherwise, the following code is self explanatory:
# Import required modules import sys, time from PySide.QtGui import * # Our main window class class MainWindow(QMainWindow): # Constructor function def __init__(self, fileName=None): super(MainWindow,self).__init__() self.initGUI() def initGUI(self): self.setWindowTitle("A Simple Text Editor") self.setWindowIcon(QIcon('appicon.png')) self.setGeometry(100, 100, 800, 600) self.textEdit = QTextEdit() self.setCentralWidget(self.textEdit) self.fileName = None self.filters = "Text files (*.txt)" self.SetupComponents() self.show() # Function to setup...