[Qt-interest] Reasoning behind size-policy difference between layout and splitter?

K. Frank kfrank29.c at gmail.com
Sat Mar 27 03:38:04 CET 2010


Hello All -

I am trying to develop intuition for the Qt way of doing things, and I have a
question about layouts vs. splitters.

Let me ask the question by giving a concrete example:

In Qt designer, I drop two QPushButton's side by side, and below them,
two QTableView's side by side onto a top-level QWidget.  I group the two
QPushButton's into a horizontal layout.  The two QTableView's I group
together into either a) a horizontal layout, or b) a horizontal splitter.

I then group the pair of QPushButton's and the pair of QTableView's into
a vertical layout, and then apply a vertical layout to the top-level widget.

In case a (the QTableView's are in a horizontal layout), when I resize the
form I get the behavior I would expect:  When I resize the form horizontally,
the QPushButton's and QTableView's widen symmetrically horizontally; and
when I resize the form vertically, the QPushButton's remain the same size
vertically, and the QTableView's expand vertically to take up the additional
space.

In case b (the QTableView's are in a horizontal splitter), I get (for
me) unexpected
behavior:  both the QPushButton's and the QTableView's expand vertically,
and end up taking about the same amount of space.

Now there is no particular reason that my expectations should be correct,
but the thing that surprised me most about this is the difference in behavior
between the horizontal layout and the horizontal splitter.  I guess I expected
that in both cases the resizing behavior of the QTableView would control the
result, and that using a splitter instead of a layout wouldn't change the basic
behavior.

Could someone offer me some guidance on the philosophy and internal logic
of Qt's resizing system, especially in the context of Qt designer?  I'm not
getting much insight from the documentation I have.

I am aware that (at least in this situation) changing the sizePolicy
of the splitter
to "Expanding, Expanding" from its default setting of "Expanding, Preferred"
makes the splitter behave like the layout.  But knowing about that setting,
and being able to change it, still isn't giving me the intuition about how the
resizing framework is designed to work.

Any insight into how this stuff all fits together, or references to
helpful documentation
will be appreciated.

Thanks.


K. Frank



More information about the Qt-interest-old mailing list