所以目前Sublayout1和Sublayout2的大小是相等的。但是我想让 Sublayout1 的宽度变小,而 Sublayout2 的宽度变大。有没有办法动态地做而不是固定大小。就像在 Android Studio 上一样,您可以在其中设置布局中元素的权重。
同样影响大小也不应该影响 Bottomlayout。非常感谢您的帮助。代码片段是:
sublayout1 = QtGui.QVBoxLayout()
sublayout2 = QtGui.QVBoxLayout()
plotBox = QtGui.QHBoxLayout()
plotBox.addLayout(sublayout1)
plotBox.addLayout(sublayout2)
bottomlayout = QtGui.QHBoxLayout()
mainlayout.addLayout(plotBox)
mainlayout.addLayout(bottomlayout)
最佳答案
使用传递给 QBoxLayout::addLayout
的 stretch
参数
sublayout1 = QtGui.QVBoxLayout()
sublayout2 = QtGui.QVBoxLayout()
plotBox = QtGui.QHBoxLayout()
plotBox.addLayout(sublayout1, 1)
plotBox.addLayout(sublayout2, 2)
bottomlayout = QtGui.QHBoxLayout()
mainlayout.addLayout(plotBox)
mainlayout.addLayout(bottomlayout)
在上面的 sublayout2
中,stretch 是 sublayout1
的两倍,因此应该分配更多空间。
关于python - PyQt,如何更改 BoxLayout 的权重(大小),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39449531/