[PyQt] Newbie resizing dock widgets question

David Boddie david at boddie.org.uk
Wed Apr 27 00:17:49 BST 2011

On Wednesday 27 April 2011, Sarah Mount wrote:
> On Tue, Apr 26, 2011 at 21:45, David Boddie <david at boddie.org.uk> wrote:
> >
> > Which version of Qt Designer are you using? Did you manually place the
> > dock widget into a layout?
> This is Designer 4.7.2 on Ubuntu Natty and the docks are going inside
> a Main Window widget, with a grid layout applied to them.

OK. You should try to avoid using layouts to arrange the dock widgets
themselves. It's fine to arrange the contents of the dock widgets using
layouts, of course.

> > If you have a dock window embedded in a main window, and you can't move
> > it when you preview the form, try breaking the layout of the window,
> > selecting the dock widget, and setting its docked property to true. It
> > should appear in one of the dock areas around the sides of the window and
> > be handled separately to the widgets in the main window itself.
> This seems to be the problem, and like you say, if I break the layout
> and set the widgets to docked they become resizable, oddly.

Yes, this sounds like they were placed in the central area of the main
window and arranged using a layout.

> However, I have three QDockWidgets, one that is intended to stretch
> over the bottom of the main window, and the other two above it side by
> side, like this:
> [][]
> [  ]

OK, it sounds like you need to tell the top two dock widgets to occupy
the top area - set their dockWidgetArea properties to TopDockWidgetArea
in the property editor and check their docked properties. The other dock
widget should be placed in the BottomDockWidgetArea.

> I've set all of the sizePolicy properties to Expanding; the lower
> dockWidget expands correctly both horizontally and vertically. The top
> two widgets will expand vertically but leave a large gap in the centre
> of the main window when resizing the main window horizontally. This
> worked just fine when I was applying a grid layout to the
> centralWidget. Any ideas?

Using the instructions above, you should now be able to resize them to fill
the window in the way you want, but I'm not sure if it's possible to get
them to expand in the way you describe. It depends on what they contain.

> It all seems a bit counter-intuitive to me! 

Maybe the diagram on this page will help to explain things:


The "center widget" or central area in the main window is a normal widget
that you can place any other widgets in. This includes dock widgets, but
they aren't designed to be used like that. They are supposed to be managed
separately by the main window, "outside" the central area. Qt Designer does
a reasonable job of letting you configure this, but it is constrained by its
widgets-on-a-form approach to UI design.

If it turns out that you aren't using all the features of dock widgets in
your application, you can design the kind of UI you describe using splitters
instead. If you want to do that, just ask and I can give more details.


More information about the PyQt mailing list