[Qt-interest] QGroupBox with a MultiCell Widget
Andreas Pakulat
apaku at gmx.de
Wed Apr 29 17:23:57 CEST 2009
On 29.04.09 10:55:38, Jake Colman wrote:
> >>>>> "AP" == Andreas Pakulat <apaku at gmx.de> writes:
>
> AP> On 29.04.09 09:00:50, Jake Colman wrote:
> >> >>>>> "AP" == Andreas Pakulat <apaku at gmx.de> writes:
> >>
> AP> On 28.04.09 23:13:24, Jake Colman wrote:
> >> >>
> >>
> >> >> I want to layout a QGroupBox in a grid but I need one of the
> >> >> widgets to be multi-cell the way it would be in a QGridLayout.
> >> >> The QGroupBox API does not support this. Is there a way to create
> >> >> the QGroupBox and have it use a QGridLayout that contains my
> >> >> widgets? If I create the QGroupBox without a layout, I cannot use
> >> >> its layout() method to be the parent of a QGridLayout() since
> >> >> layout() returns NULL. If I create the QGroupBox() with some
> >> >> bogus layout (e.g., 1 horizontal strip) the layout() method will
> >> >> return a value. Is it legitimate that use that value as the
> >> >> parent of a QGridLayout and will that QGridLayout supercede the
> >> >> bogus layout in the QGroupBox?
> >>
> AP> Why not use QGroupBox::setLayout( new GridLayout() )? That should
> AP> work just fine (and thats actually what happens in
> AP> designer-generated code when you create a groupbox and set a
> AP> gridlayout on it).
> >>
> >> If it only it were that simple...
> >>
> >> I am still on Qt 3.x and setLayout() is not an exposed method of
> >> QWidget.
>
> AP> Well, then simply construct the QGridLayout with the QGroupBox as
> AP> parent, it'll set itself as layout for the groupbox and as you
> AP> said the groupbox doesn't have a layout yet at that time this
> AP> should be perfectly ok.
>
> Andrea,
>
> So you are suggesting the following:
>
> QGroupBox* GB = new QGroupBox( "Definition", this, "GB" );
> QGridLayout* GL = new QGridLayout( GB, 2, 5, 0, -1, "GL" );
>
> How do I create the widgets that are supposed to be contained in the GB
> and laid out in specific cells of the GL? Are the widgets parented by
> GB
Yes.
> and then I use GL->addWidget() to position them in the grid? I
> played with different things but cannot get it to work quite right.
Hmm, looking at the designer generated code it seems to do what you
initialy suggest, it calls setColumnLayout(0, Qt::Vertical) and then later
uses QGoupBox::layout() as parent layout for the grid. So I'm guess thats
the only way to do it.
Andreas
--
You fill a much-needed gap.
More information about the Qt-interest-old
mailing list