PyQT5 (五十七) QMdiArea 容纳多文档的窗口 的案例

PyQT5 (五十七) QMdiArea 容纳多文档的窗口 的案例

 PyQT5 (五十七) QMdiArea 容纳多文档的窗口 的案例

 QMdiArea 容纳多文档的窗口 的案例
QMdiSubWindow

import sys

from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication, QWidget, QTableWidget, QTableWidgetItem, QMenu, QVBoxLayout, QMainWindow, \
    QTreeWidget, QTreeWidgetItem, QHBoxLayout, QPushButton, QInputDialog, QDirModel, QTreeView, QTabWidget, QFormLayout, \
    QLineEdit, QRadioButton, QLabel, QCheckBox, QListWidget, QStackedWidget, QDockWidget, QMdiArea, QMdiSubWindow, \
    QTextEdit

'''
QMdiArea 容纳多文档的窗口 的案例
QMdiSubWindow

'''


class MultiWindows(QMainWindow):
    count = 0
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        # 设置定位和左上角坐标
        self.setGeometry(300, 300, 360, 360)
        # 设置窗口标题
        self.setWindowTitle('QMdiArea 容纳多文档的窗口 的演示')
        # 设置窗口图标
        # self.setWindowIcon(QIcon('../web.ico'))

        self.mdi = QMdiArea()
        self.setCentralWidget(self.mdi)
        bar = self.menuBar()
        file = bar.addMenu("File")
        file.addAction("New")
        file.addAction("cascade")
        file.addAction("Tiled")

        file.triggered.connect(self.windowaction)

    def windowaction(self,q):
        print(q.text())
        if q.text() == "New":
            MultiWindows.count = MultiWindows.count+1
            sub = QMdiSubWindow()
            sub.setWidget(QTextEdit())
            sub.setWindowTitle("子窗口"+str(MultiWindows.count))
            self.mdi.addSubWindow(sub)
            sub.show()
        elif q.text() == 'cascade':
            self.mdi.cascadeSubWindows()
        elif q.text() == 'Tiled':
            self.mdi.tileSubWindows()



if __name__ == '__main__':
    app = QApplication(sys.argv)
    # 设置应用图标
    app.setWindowIcon(QIcon('../web.ico'))
    w = MultiWindows()
    w.show()
    sys.exit(app.exec_())

上一篇:Error: one input ui-file must be specified 已经解决


下一篇:PyQt5 QFileDialog迟滞问题临时解决