[Qt-interest] More struggles with layouts and resizing -- QGroupBox gets squashed
K. Frank
kfrank29.c at gmail.com
Sun Mar 28 17:48:13 CEST 2010
To All -
I'm still trying to figure out how to use resizing most effectively.
I will give a
concrete example and ask a general question.
The example:
I layout a form that contains a QGroupBox, but the QGroupBox (and its contents)
get squashed.
I create a new QWidget-based form in designer, and drop a QTableView onto it
towards the bottom.
In case a, I add two QRadioButton's, one above the other, above the QTableView,
and group them together into a vertical layout.
In case b, I add a QGroupBox above the QTableView, and then add two
QRadioButton's
to the QGroupBox.
I now set the top-level layout of the QWidget to a vertical layout.
In case a (the
two QRadioButton's are in a vertical layout), everything resizes nicely: The
QTableView takes up most of the space, with the two QRadioButton's nicely
sized above it.
In case b (the QRadioButton's are in a QGroupBox), the QTableView expands
(as expected), but the QGroupBox shrinks down to the point that only its title
is visible, and its contents (the QRadioButton's) are hidden.
The default sizePolicy of QGroupBox is "Preferred, Preferred", so I
tried changing
it to "Expanding, Expanding". Now things go too far the other way --
the QGroupBox
expands to take up about half the space, much more space than is needed for the
QRadioButton's.
That's my concrete example. Is there a better way to get a QGroupBox -- and
its contents -- to resize nicely?
My general question:
Layouts seem to resize nicely -- they know about or inherit the size policies of
their contents, and the default size policies of individual widgets seem to be
sensible choices for most purposes.
It seems like my main misconception is that I sort of expect widgets
-- including
container widgets -- to have some of the same nice resizing behavior as layouts.
But instead, widgets seem to hide or not to know about the resizing behavior of
their contents. This makes Qt's automatic resizing framework not so useful for
more complicated forms that include container widgets as well as layouts.
Two specific examples I've come across are the one above (where a QGroupBox
doesn't resize as nicely as a layout), and one I asked about in a
previous posting,
where a splitter doesn't resize as nicely as a layout.
Do I misunderstand something here, maybe having missed some important concept?
What have people found to be a good strategy for resizing when designing more
complicated forms, especially those that include container widgets?
Thanks for sharing your experience.
K. Frank
More information about the Qt-interest-old
mailing list