[PyQt] Stacking QWidgets vertically?

Mark Summerfield list at qtrac.plus.com
Mon Sep 21 17:25:17 BST 2009


On 2009-09-21, Mark Summerfield wrote:
> On 2009-09-21, Kurt Schwarz wrote:
> > A QSplitter isn't what I am looking for because "A splitter lets the
> > user control the size of child widgets by dragging the boundary
> > between the children." I don't want the user to be able to re-size the
> > widgets, sorry if I wasn't clear about this before.
> >
> > Here is a picture to better illustrate what I am looking for:
> > http://img89.imageshack.us/img89/8837/83828522.png
> >
> > In this example I have to set the x, y cords manually im looking for
> > something more automated as those boxes are generated with dynamic
> > heights.
> 
> Using a QVBoxLayout seems reasonable to me.
> 
> Suppose your widgets are:
> 
>     widget1 = QWidget() # could be a dummy widget (this will occupy
> 			# the big red area)
>     widget2 = ... # this is the one that is about 1/2 as tall as the
> 		  # other two
>     widget3 = ... # one from bottom
>     widget4 = ... # bottom
> 
> You might find this works (untested):
> 
>     layout = QVBoxLayout()
>     layout.addWidget(widget1, 10) # these ints are stretch factors
>     layout.addWidget(widget2, 1)  # they say how much space the widgets
>     layout.addWidget(widget3, 3)  # should get in proportion to each
>     layout.addWidget(widget4, 2)  # other
> 
> You can also set minimum sizes (e.g., heights) & size policies for the
> widgets---all of which should be enough to get what you want.
> 
> (I missed any earlier emails, so sorry if you've already tried this.)
> 


-- 
Mark Summerfield, Qtrac Ltd, www.qtrac.eu
    C++, Python, Qt, PyQt - training and consultancy
        "Rapid GUI Programming with Python and Qt" - ISBN 0132354187


More information about the PyQt mailing list