PyQt5 Make Multi Document Interface (MDI) Application

PyQt5 Make Multi Document Interface (MDI) Application – In this PyQt5 article we are

going to Make Multi Document Interface (MDI) Application.

so first of all lets have some basic information about Multi Document Interface (MDI) window.

 

 

 

Also you can check more Python GUI articles in the below links

1: Kivy GUI Development Tutorials

2: Python TKinter GUI Development 

3: Psyide2 GUI Development 

4: wxPython GUI Development 

5: PyQt5 GUI Development Course

 

 

 

 

SDI & MDI Application 

In many GUI applications, we will arrive at a situation where we need to open more
than one document at a time to process them. We will want to design our application
to handle this. This can be achieved by either of two approaches, namely, SDI and
MDI. A Single Document Interface (SDI) application implements this by creating
separate windows for each of the documents. This is done by creating a window
subclass that handles everything by itself, including loading, saving, cleaning up,
and so on. Each of the documents will be a clone of the main window having a
separate menu bar, toolbar, and status bar on its own. Each of the main window
instances must be able to act independently. However, there are some disadvantages
to this approach. This approach consumes a lot of resources and it would be very
inconvenient to open many windows at a time and keep track of them.
The second approach is to use a Multiple Document Interface (MDI) application
where the central widget is instantiated with multiple instances. All these widgets
will be interrelated within the main window and share the common menu bar,
toolbar, and other components. MDI applications will use lesser resources compared
with SDI applications. The MDI applications are provided with an extra menu to
manage between windows because shifting between them is not controlled by the
underlying operating system.

 

 

 

 

Implementation of MDI Application

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 

PyQt5.QtWidget.QMdiArea  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 . An example of the MDI application is given as follows:

 

 

 

 

Complete code for PyQt5 Make Multi Document Interface (MDI) Application.

 

 

 

 

What is QMdiArea Class ?

QMdiArea functions, essentially, like a window manager for MDI windows. For instance,

it draws the windows it manages on itself and arranges them in a cascading or tile pattern. QMdiArea is commonly used as the center widget in a QMainWindow to create

MDI applications, but can also be placed in any layout. The following code adds an area to a

main window.

 

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:

 

 

PyQt5 Make Multi Document Interface (MDI) Application
PyQt5 Make Multi Document Interface (MDI) Application

 

 

 

 

This is the cascade mode

PyQt5 MDI Cascade Mode
PyQt5 MDI Cascade Mode

 

 

 

 

This is the tiled mode

PyQt5 MDI Window Tiled Mode
PyQt5 MDI Window Tiled Mode

 

 

 

 

 

 

Also you can watch the complete video for this article

Subscribe and Get Free Video Courses & Articles in your Email

 

3 thoughts on “PyQt5 Make Multi Document Interface (MDI) Application”

Comments are closed.

Share via
Copy link
Powered by Social Snap
×