示例#1
0
class Window(QMainWindow):
    def __init__(self):
        super(Window, self).__init__()

        self.setWindowTitle("Pyside2 Simple Application")
        self.setGeometry(300, 300, 300, 300)
        self.mdi = QMdiArea()
        self.setCentralWidget(self.mdi)
        menu_bar = self.menuBar()
        file = menu_bar.addMenu("File")
        new = QAction("New", self)
        new.triggered.connect(self.newSlot)
        file.addAction(new)
        cascade = QAction("Cascade", self)
        cascade.triggered.connect(self.cascadeAction)
        file.addAction(cascade)
        tiled = QAction("Tiled", self)
        tiled.triggered.connect(self.tileAction)
        file.addAction(tiled)
        self.count = 0

    def newSlot(self):
        self.count += 1
        sub = QMdiSubWindow()
        sub.setWidget(QTextEdit())
        sub.setWindowTitle("Sub Window " + str(self.count))
        self.mdi.addSubWindow(sub)
        sub.show()

    def cascadeAction(self):
        self.mdi.cascadeSubWindows()

    def tileAction(self):
        self.mdi.tileSubWindows()
示例#2
0
class Window(QMainWindow):

    count = 0

    def __init__(self):
        super().__init__()
        self.init_ui()

    def init_ui(self):
        self.setWindowTitle("Pyside2 MDI Window")
        self.setGeometry(100, 100, 900, 500)
        self.setWindowIcon(QIcon('icon.png'))

        self.mdi = QMdiArea()
        self.setCentralWidget(self.mdi)

        menu_bar = self.menuBar()

        file = menu_bar.addMenu("File")
        file.addAction("New")
        file.addAction("Cascade")
        file.addAction("Tiled")

        file.triggered[QAction].connect(self.windowTriggered)

    def windowTriggered(self, p):
        if p.text() == "New":
            Window.count = Window.count + 1
            sub = QMdiSubWindow()
            sub.setWidget(QTextEdit())
            sub.setWindowTitle("Sub Window " + str(Window.count))
            self.mdi.addSubWindow(sub)
            sub.show()

        if p.text() == "Cascade":
            self.mdi.cascadeSubWindows()

        if p.text() == "Tiled":
            self.mdi.tileSubWindows()
示例#3
0
class WindowWidget(QMainWindow):
    def __init__(self):
        super().__init__()
        self.init_ui()

    def init_ui(self):
        self.formCoin = None
        self.formCliente = None

        # title, geoemtry and icon for this window
        self.setWindowTitle("Pyside2 MDI Window")
        self.setGeometry(100, 100, 900, 500)
        self.setWindowIcon(QIcon("pyicon.png"))

        # creating object of MDI
        self.mdi = QMdiArea()
        self.setCentralWidget(self.mdi)

        # our menu bar
        menu_bar = self.menuBar()

        # our menu items
        file = menu_bar.addMenu("File")
        file.addAction("Coin")
        file.addAction("Cliente")
        file.addAction("Cascade")
        # file.addAction("Tiled")
        file.triggered[QAction].connect(self.window_triggered)
        self.showMaximized()

    def loadSubWindow(self, widget):
        window = self.mdi.addSubWindow(widget)
        window.setFixedSize(window.size())
        window.setWindowFlags(
            QtCore.Qt.Dialog
            | QtCore.Qt.WindowCloseButtonHint
            | QtCore.Qt.WindowMinimizeButtonHint
            | QtCore.Qt.CustomizeWindowHint
        )
        window.move(
            (self.mdi.width() - window.width() - 10) / 2,
            (self.mdi.height() - window.height() - 90) / 2,
        )
        window.show()

    def findMdiChild(self, fileName):
        for window in self.mdi.subWindowList():
            if window.widget().windowTitle() == fileName:
                return window
        return None

    def window_triggered(self, p):
         if p.text() == "Coin":
            existing = self.findMdiChild('Coin')
            if existing is None:
                self.formCoin = Coin("coin.ui")
                self.loadSubWindow(self.formCoin)
            else:
                self.formCoin.setFocus()
 
         if p.text() == "Cliente":
            existing = self.findMdiChild('Cliente')
            if existing is None:
                self.formCliente = Cliente("clienteform.ui")
                self.loadSubWindow(self.formCliente)
            else:
                self.formCliente.setFocus()

         if p.text() == "Cascade":            
             self.mdi.cascadeSubWindows()
         if p.text() == "Tiled":
             self.mdi.tileSubWindows()