Skip to content

Instantly share code, notes, and snippets.

@jeakwon
Created June 26, 2020 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeakwon/e5911e3119407065fb37adf492b54289 to your computer and use it in GitHub Desktop.
Save jeakwon/e5911e3119407065fb37adf492b54289 to your computer and use it in GitHub Desktop.
PySide2 subwindow
from PySide2.QtWidgets import QApplication, QMainWindow, QMdiArea, QAction, QMdiSubWindow, QTextEdit
import sys
class MDIWindow(QMainWindow):
count = 0
def __init__(self):
super().__init__()
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[QAction].connect(self.WindowTrig)
self.setWindowTitle("MDI Application")
def WindowTrig(self, p):
if p.text() == "New":
MDIWindow.count = MDIWindow.count + 1
sub = QMdiSubWindow()
sub.setWidget(QTextEdit())
sub.setWindowTitle("Sub Window" + str(MDIWindow.count))
self.mdi.addSubWindow(sub)
sub.show()
if p.text() == "cascade":
self.mdi.cascadeSubWindows()
if p.text() == "Tiled":
self.mdi.tileSubWindows()
app = QApplication(sys.argv)
mdi =MDIWindow()
mdi.show()
app.exec_()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment