[PyQt] Using layouts in a tab widget

Andreas Pakulat apaku at gmx.de
Sun Apr 24 13:11:49 BST 2011


On 24.04.11 07:10:24, Sarah Mount wrote:
> Sorry if this is an obvious question, but I couldn't find an answer to
> it on the using-containers page or on StackOverflow. I have a bunch of
> tab widgets that need to have appropriate layouts applied to them and
> to the tabs they contain. Working with the .ui files in Qt4 Designer,
> I notice that if I click on an individual tab inside the tab widget,
> then it is by default marked as "break layout", like every other
> widget. If I then try to apply a layout to the tab, the layout instead
> gets applied to the whole tab widget. So, to get around this I could
> put a GroupBox or Frame inside each tab and give that a layout, but
> this seems long-winded. Is there something obvious I have missed or
> does Qt assume that each tab will have a container widget placed
> inside it?

I think I'm misunderstanding something, if I click on tab in designer
and select a layout that layout is applied to all widgets in the
client-space of the tab. Its not applied to the tabwidget, i.e. it does
not lay out the tabwidget with all sibling-widgets you may have in the
base widget.

You can select a different tab and apply a different layout to that tabs
client space using the same procedure. This is also reflects in the
object tree, where you can see an imaginary intermediate QWidget between
the tabwidget and all the widgets you place inside the client space. And
thats where the layout is applied.

If you need to layout different groups of widgets inside the tabwidget
with different layouts, you select those that should get into the same
layout and layout them. Then you select a layout for the whole
client-space. You can also layout groups of other layouts of course.

Andreas



More information about the PyQt mailing list