gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 11:16:37 28 4
gpt4 key购买 nike

我想用QSplitterQMdiarea应用到QMainwindow,关于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_())

显示: enter image description here

我想实现的:结果展示

enter image description here

感谢任何帮助。

最佳答案

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

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

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com