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_())
标签:__,mdi,QMdiArea,self,PyQT5,MultiWindows,file,五十七 来源: https://blog.csdn.net/gixome/article/details/120928239