PYQT5 learning (13): QMidArea simultaneously display multiple windows, create multiple independent windows

QMidArea Reference article: https://blog.csdn.net/jia666666/article/details/81670569

Method for simultaneously displaying multiple windows, create multiple independent windows, these separate window is called SDI (single document interface single-document interface), each window has its own menu system, toolbars, etc., which requires take up a lot of resources.

MDI (multiple document interface Multiple Document Interface) application consumes less memory resources, the sub-window can be placed in the container main window, the container space is called QMidArea

QMidArea space normally occupied QMainWindow at a central position of the object, in this region is a child window QMidSubWindow class instance may be provided as an internal control QWidget any child window object, arranged in cascade the sub-window layout area MDI

 

import sys
from PyQt5.QtWidgets import QApplication,QMainWindow,QMdiArea,QMdiSubWindow,QLabel

class MidArea(QMainWindow):
    def __init__(self):
        
        super().__init__()
        self.initUI()
    def initUI(self):
        self.setWindowTitle('demo')
        self.setGeometry(300,300,300,200)

        bar=self.menuBar()
        file=bar.addMenu('File')
        file.addAction('new')
        file.addAction('cascade')
        file.addAction('tile')
        file.triggered.connect(self.showWindow)
        

        #------定义QMdiArea,用来放置子窗口------
        self.area=QMdiArea()
        self.setCentralWidget(self.area)


    showWindow DEF (Self, Data): 
        text = data.text () 
        IF == text 'new new': 
          
            # Create a new window 
            subwindow QMdiSubWindow = () 
            # add child window assembly 
            subwindow.setWindowTitle ( 'which is QMdiSubWindow') 
            subwindow.setWidget (the QLabel ( 'Hello')) 
            # adds the word to the window area QmdiArea 
            self.area.addSubWindow (subwindow) 
            # subwindow display 
            subwindow.show () 
        IF text == 'cascade': 
            # display settings window cascade 
            self.area.cascadeSubWindows () 
        
        IF text == 'the tile': 
            # settings window tile 
            self.area.tileSubWindows () 
            



IF __name__ __ == '__ main__': 
    App = the QApplication (the sys.argv)
   
    demo=MidArea()
    demo.show()
    sys.exit(app.exec_())

  Renderings: Create a new cascade effect --------- ------- tiling effect

 

Guess you like

Origin www.cnblogs.com/cgy1995/p/11127195.html