带有QSplitter和QMainWindow的应用程序QMdiarea

时间:2019-07-03 12:43:09

标签: python pyqt pyqt5 qmainwindow qmdiarea

我想将QMdiarea应用于QMainwindow的{​​{1}}上,关于QSplitter的帖子很少,但没有一个真正说明如何应用于此类{{ 1}}。

我的代码:

QMdiarea

显示: enter image description here

我想要实现的是:结果显示

enter image description here

感谢您的帮助。

1 个答案:

答案 0 :(得分:3)

您必须创建一个QMdiArea,将其设置为centralWidget,然后使用addSubWindow()方法添加mainSplitter:

class Mywindow(QtWidgets.QMainWindow):
    def __init__(self, parent=None):
        super(Mywindow, self).__init__(parent)

        self.setMinimumSize(QtCore.QSize(1200, 800))
        self.setWindowTitle("MdiArea")

        self.mdiarea = QtWidgets.QMdiArea()
        self.setCentralWidget(self.mdiarea)

        self.groupone = QtWidgets.QTextEdit()
        self.grouptwo = QtWidgets.QListWidget()
        self.groupthree = QtWidgets.QTextEdit()
        self.groupfour = QtWidgets.QListWidget()

        self.V_Splitter = QtWidgets.QSplitter(QtCore.Qt.Vertical)
        self.V_Splitter.addWidget(self.groupone)
        self.V_Splitter.addWidget(self.grouptwo)

        self.viewSplitter = QtWidgets.QSplitter(QtCore.Qt.Vertical)
        self.viewSplitter.addWidget(self.groupthree)
        self.viewSplitter.addWidget(self.groupfour)

        self.mainSplitter = QtWidgets.QSplitter(QtCore.Qt.Horizontal)
        self.mainSplitter.addWidget(self.V_Splitter)
        self.mainSplitter.addWidget(self.viewSplitter)

        self.mainSplitter.setStretchFactor(0, 1)
        self.mainSplitter.setStretchFactor(1, 5)
        self.viewSplitter.setStretchFactor(0, 1)
        self.viewSplitter.setStretchFactor(1, 1)

        self.mdiarea.addSubWindow(self.mainSplitter)
        # ...

enter image description here