我正在PyQt5中构建一个GUI。其结构将如下图所示。
我需要的是在窗口调整大小时管理:
以下是此示例的代码:
def initUI(self):
topHBoxLayout = QHBoxLayout(self)
topHBoxLayout.setContentsMargins(0,0,0,0)
sstFrame = QFrame()
sstFrame.setMinimumSize(QSize(100, 100))
self.colorFrame(sstFrame, 'red')
objectivesFrame = QFrame()
objectivesFrame.setMinimumSize(QSize(100, 100))
self.colorFrame(objectivesFrame, 'green')
wsTop = QFrame()
wsTop.setMinimumSize(QSize(100, 100))
self.colorFrame(wsTop, 'blue')
wsBottom = QFrame()
wsBottom.setMinimumSize(QSize(100, 100))
self.colorFrame(wsBottom, 'purple')
workspaceSplitter = QSplitter(Qt.Vertical)
workspaceSplitter.addWidget(wsTop)
workspaceSplitter.addWidget(wsBottom)
mainSplitter = QSplitter(Qt.Horizontal)
mainSplitter.addWidget(sstFrame)
mainSplitter.addWidget(objectivesFrame)
mainSplitter.addWidget(workspaceSplitter)
topHBoxLayout.addWidget(mainSplitter)
self.setLayout(topHBoxLayout)
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('')
self.show()
感谢您的任何建议,我无法自己解决。
答案 0 :(得分:0)
无论我尝试了什么,我都无法为连接到单个拆分器实例的三个小部件做任何工作(我尝试过SizePolicy设置,QSplitter伸展因子......)。
所以试图用更少的QFrame包装它,似乎工作。但我仍然打开原始代码的解决方案。
这是我的结果:
def initUI(self):
topHBoxLayout = QHBoxLayout(self)
topHBoxLayout.setContentsMargins(0,0,0,0)
sstObjWrapper = QSplitter(Qt.Horizontal)
sstObjWrapper.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
sstFrame = QFrame()
sstFrame.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
sstFrame.setMinimumSize(QSize(100, 100))
self.colorFrame(sstFrame, 'red')
# --- sst frame ---
objectivesFrame = QFrame()
objectivesFrame.setMinimumSize(QSize(100, 100))
objectivesFrame.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
self.colorFrame(objectivesFrame, 'green')
sstObjWrapper.addWidget(sstFrame)
sstObjWrapper.addWidget(objectivesFrame)
tmp1 = QFrame(self)
tmp1.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
tmp1.setMinimumSize(QSize(200, 200))
self.colorFrame(tmp1, 'purple')
tmp2 = QFrame(self)
tmp2.setMinimumSize(QSize(100, 100))
tmp2.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.colorFrame(tmp2, 'blue')
plotConsoleSplitter = QSplitter(Qt.Vertical)
plotConsoleSplitter.addWidget(tmp1)
plotConsoleSplitter.addWidget(tmp2)
plotConsoleSplitter.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
objPlotSplitter = QSplitter(Qt.Horizontal)
objPlotSplitter.addWidget(sstObjWrapper)
objPlotSplitter.addWidget(plotConsoleSplitter)
objPlotSplitter.setStretchFactor ( 0, 0 )
objPlotSplitter.setStretchFactor ( 1, 1 )
topHBoxLayout.addWidget(objPlotSplitter)
self.setLayout(topHBoxLayout)
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('')
self.show()