I have a Gui layout as in the picture.
So currently Sublayout1 and Sublayout2 are equal in size. However I want to make Sublayout1's width smaller and stretch Sublayout2's width bigger. Is there a way to do it dynamically instead of putting a fixed size. Like on Android Studio where you can set the weight of the elements within the layout.
Also affecting the size shouldn't affect the Bottomlayout either. Many thanks for your help. A snippet of the code is:
sublayout1 = QtGui.QVBoxLayout()
sublayout2 = QtGui.QVBoxLayout()
plotBox = QtGui.QHBoxLayout()
plotBox.addLayout(sublayout1)
plotBox.addLayout(sublayout2)
bottomlayout = QtGui.QHBoxLayout()
mainlayout.addLayout(plotBox)
mainlayout.addLayout(bottomlayout)
Use the stretch
parameter passed to QBoxLayout::addLayout
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)
In the above sublayout2
has a stretch twice that of sublayout1
and so should be allocated more space.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With