我想将QMdiarea应用于QMainwindowQSplitter,关于QMdiarea的帖子很少,但没有一篇真正说明如何应用于此类QtWidgets

我的代码:

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

        self.setMinimumSize(QtCore.QSize(1200,800))
        self.setWindowTitle('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.setCentralWidget(self.mainSplitter)

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

        # Center window
        qtRectangle = self.frameGeometry()
        centerPoint = QtWidgets.QDesktopWidget().availableGeometry().center()
        qtRectangle.moveCenter(centerPoint)
        self.move(qtRectangle.topLeft())

if __name__ == '__main__':
    import sys

    app = QtWidgets.QApplication(sys.argv)
    app.setStyle('Fusion')
    sim = Mywindow()
    sim.showMaximized()
    sys.exit(app.exec_())


显示:
python - 带有QSplitter和QMainWindow的QMdiarea应用程序-LMLPHP

我要达到的目标:结果显示

python - 带有QSplitter和QMainWindow的QMdiarea应用程序-LMLPHP

感谢您的帮助。

最佳答案

您必须创建一个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)
        # ...


python - 带有QSplitter和QMainWindow的QMdiarea应用程序-LMLPHP

关于python - 带有QSplitter和QMainWindow的QMdiarea应用程序,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56870440/

10-08 21:43