Implementation of MDI

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

A Multiple Document Interface application will be a main windowed application with their central widgets can be one of PySide.QtGui.QMdiArea or PySide.QtGui.QWorkSpace widget. They are by itself a widget component, which manages the central area of main window to arrange the MDI windows in a layout. Sub-windows can be created and added to the MDI area or a workspace. An example of the MDI application is 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 preceding screenshot shows the placement of windows in a cascaded view. The following one implements the same example but in a tile view:

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
3.145.107.100