Implementation of MDI

We have already discussed the differences between SDI and MDI applications in Chapter 3, Main Windows and Layout Management. We saw many implementations of SDI applications. In this section, we will explore a technique of creating MDI applications.

A Multiple Document Interface application will consist of a main window where multiple child windows and dialogs reside and appear for interaction. The central widget can be either the PySide.QtGui.QMdiArea or PySide.QtGui.QWorkSpace widget. They are by themselves widget components that manage the central area of the main window to arrange the MDI windows in a layout. Subwindows are then created and added to the MDI area or a workspace. An example of the MDI application is given as follows:

class MyMDIApp(QMainWindow):
    
    def __init__(self):
        QMainWindow.__init__(self)

        workspace = QWorkspace()
        workspace.setWindowTitle("Simple WorkSpace Example")

        for i in range(5):
            textEdit = QTextEdit()
            textEdit.setPlainText("Dummy Text " * 100)
            textEdit.setWindowTitle("Document %i" % i)
            workspace.addWindow(textEdit)

        workspace.tile()
        self.setCentralWidget(workspace)

        self.setGeometry(300, 300, 600, 350)
        self.show()

The MDI windows inside a main windowed application can be set in a cascade or tile layout by default or a customized layout can be specified. The following screenshots show the two types of layout of the example application:

Implementation of MDI

The following screenshot depicts another layout for the display of the child windows:

Implementation of MDI
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.181.57