Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt, How to change BoxLayout's weight (size)

Tags:

python

qt

pyqt

I have a Gui layout as in the picture. enter image description here

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)
like image 792
J_yang Avatar asked Dec 19 '22 13:12

J_yang


1 Answers

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.

like image 140
G.M. Avatar answered Dec 21 '22 03:12

G.M.