[Qt-interest] How does Qt designer manage resizing widgets at design time?

Andreas Pakulat apaku at gmx.de
Mon Mar 22 01:06:39 CET 2010


On 21.03.10 18:46:43, K. Frank wrote:
> >> Is there any (easy) way to get
> >> my place-holder widget (in my test case, a QWidget) to mimic in Qt designer
> >> more closely QTableWidget (or my custom widget)?
> >
> > A simple work-around for the sizing of promoted widgets issue in
> > designer is to manually alter the size policy for the widget.
> >
> > Sean
> 
> This is not that big a deal for me -- it's a matter of minor convenience, and
> more importantly to help me better learn the tricks of the Qt trade.
> 
> To be concrete, in Qt designer, I drop a QTreeView, a QTableWidget, and
> a QTableView, from left to right in that order onto a form, I group the three
> widgets together in a horizontal layout, and I apply a vertical layout to the
> background (central widget?) of the form.  The three widgets now take up
> most of the space of the form, are about the same size, and resize
> proportionately when I resize the form.  (This is all at design time.)
> 
> If I replace the QTableWdiget with a QWidget (that is, I drop a QTreeView,
> a QWidget, and a QTableView onto a blank form, and set the layouts, etc.),
> the QWidget is much skinnier than the other two widgets.
> 
> (What I really want is a custom widget that contains a QTableWdiget, so
> I am using the QWidget as a place-holder in Qt designer, and promoting
> it to my custom widget.)
> 
> If I select the QWidget and use the Property Editor to set its sizePolicy
> to "Expanding, Expanding" (from "Preferred, Preferred", to match the
> sizePolicy of the other two widgets), it gets somewhat wider, but still
> not as wide as the other two widgets.  I can also set the minimumSize
> to a value of my choice, so I can make my form look more realistic in
> designer, but the QWidget place-holder still doesn't resize the way the
> other two widgets do.
> 
> Again, this is certainly good enough for my practical needs, but I would
> like to follow up on Sean's comment, and ask if it is possible to tweak
> my QWidget place-holder so that behaves more realistically in designer.

You could try to play with the stretch factors and/or the other
size-values. But unless you provide a qt designer plugin for your custom
widget you probably won't get the same behaviour as with a real
qtablewidget. The reason is that the place-holder doesn't have the same
implementation for the sizeHint and other size-related methods.

> What confuses me a little is that when I use the Property Editor to look
> at the various properties of the three widgets, I don't see and size-related
> differences (after I set the sizePolicy for the QWidget to "Expanding,
> Expanding"), so I don't see any simple reason for them to act differently
> in designer.

The reason is that their sizeHint implementations and the various other
geometry-related methods differ.

Andreas

-- 
Don't you feel more like you do now than you did when you came in?



More information about the Qt-interest-old mailing list