[Qt-interest] Help getting out of Gridlayout Hell

Scott Aron Bloom Scott.Bloom at sabgroup.com
Sun Apr 26 23:37:26 CEST 2009


So theproblem is not the margin of the label, but rather the location of
the combo boxes...

Unfortunately, I cant think of any easy way to have a layouts
"requirements" take into account another layout...

However, here is what you could do.. and it wouldn't be too difficult...

Since all six of your labels are "fixed" (not line edits) you could lay
the two grids out, then getting the minimum size hints for each label,
and setting the size to the maximum of the minimums..

It shouldn't be too hard, and is essentially what the layout system
does.

Scott
> -----Original Message-----
> From: Jake Colman [mailto:colman at ppllc.com]
> Sent: Sunday, April 26, 2009 1:47 PM
> To: Scott Aron Bloom
> Cc: qt-interest at trolltech.com
> Subject: Re: [Qt-interest] Help getting out of Gridlayout Hell
> 
> 
> Scott,
> 
> But let's say it is not a vertical group box but one with several
> strips.  In other words:
> 
> label    combobox    label    combobox
> label    combobox    label    combobox
> label    combobox    label    combobox
> 
> I want the above layout in two different groupboxes such that the
labels
> and comboboxes are aligned.  The labels, however, are not all the same
> size.
> 
> This seems like a reasonable thing to want to do and does not seem to
> violate GUI norms.
> 
> ...Jake
> 
> 
> >>>>> "SAB" == Scott Aron Bloom <Scott.Bloom at sabgroup.com> writes:
> 
>    SAB> If I have group box A with sub layout of type vertical, and a
group
> box
>    SAB> B with a sub layout of type vertical.
>    SAB> Setting each of their margins to the same value, will have
both sets
> of
>    SAB> group boxes vertically laid out widgets line up.
> 
>    SAB> In code:
>    SAB> QWidget * widget = new QWidget;
>    SAB> QVBoxLayout * mainVb = new QVBoxLayout( widget );
> 
>    SAB> QGroupBox * gb = new QGroupBox;
>    SAB> mainVb >addWidget( gb );
>    SAB> QVBoxLayout * vb = new QVBoxLayout( gb );
> 
>    vb-> addWidget(new QLabel( "label1" ) );
>    vb-> addWidget(new QLabel( "label2" ) );
>    vb-> addWidget(new QLabel( "label3" ) );
> 
>    SAB> gb = new QGroupBox;
>    SAB> mainVb >addWidget( gb );
>    SAB> vb = new QVBoxLayout( gb );
>    vb-> addWidget(new QLabel( "label4" ) );
>    vb-> addWidget(new QLabel( "label5" ) );
>    vb-> addWidget(new QLabel( "label6" ) );
> 
>    widget-> show();
> 
>    SAB> now.. if I add a third widget, that item WILL certainly NOT
line up
> with
>    SAB> the sub lablels...
> 
>    mainVb-> addWidget( new QLabel( "label7" ) )
> 
>    SAB> And in my view it shouldn't, since you grouped the subs anyway
> 
>    SAB> Scott
> 
>    >> -----Original Message-----
>    >> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
>    >> bounces at trolltech.com] On Behalf Of Jake Colman
>    >> Sent: Sunday, April 26, 2009 1:33 PM
>    >> To: qt-interest at trolltech.com
>    >> Subject: Re: [Qt-interest] Help getting out of Gridlayout Hell
>    >>
>    >>
>    >> I'll try it but think of this another way.  How can you create
two
>    >> independent group boxes that have exactly the same alignment?
>    SAB> Remember
>    >> that a groupbox uses an internal gridlayout.  The size of each
cell in
>    >> the grid depends on the cell's contents.  Two independent
groupboxes
>    >> with independent gridlayout may end up with different sizing.
How do
>    >> you make it consistent?
>    >>
>    >>
>    >> >>>>> "SAB" == Scott Aron Bloom <Scott.Bloom at sabgroup.com>
writes:
>    >>
>    SAB> Setting the margins to 0 might help.
>    >>
>    >> >> -----Original Message-----
>    >> >> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
>    >> >> bounces at trolltech.com] On Behalf Of Jake Colman
>    >> >> Sent: Saturday, April 25, 2009 7:23 PM
>    >> >> To: qt-interest at trolltech.com
>    >> >> Subject: [Qt-interest] Help getting out of Gridlayout Hell
>    >> >>
>    >> >>
>    >> >> I have a number of widgets that need to be laid out in a
grid.
>    SAB> This
>    SAB> is
>    >> >> normally nice and simple.  The problem is that I need to use
a
>    SAB> groupbox
>    >> >> to group some of the widgets in this grid.  The problem is
that
>    SAB> the
>    >> >> widgets in the grid do not align with the widgets in the
>    SAB> groupbox.
>    SAB> How
>    >> >> do I get around this?
>    >> >>
>    >> >> This is with Qt 3.3 but I don't think layout management
changed
>    SAB> much
>    >> >> between 3.x and 4.x.
>    >> >>
>    >> >> Thanks for your help.
>    >> >>
>    >> >> ...Jake
>    >> >>
>    >> >>
>    >> >> --
>    >> >> Jake Colman | Director, Software Development
>    >> >> Principia Partners LLC
>    >> >> 101 West Elm Street | Conshohocken | PA 19428 | +1 (610) 755
>    SAB> 9770
>    >> >> t: +1 (610) 755 9786 | c: +1 (610) 348 2788 | f: +1 (201) 221
>    SAB> 8929
>    >> >> e: colman at ppllc.com | w: www.principiapartners.com
>    >> >> Credit technology innovation awards winner 2008
>    >> >>
>    >> >> _______________________________________________
>    >> >> Qt-interest mailing list
>    >> >> Qt-interest at trolltech.com
>    >> >> http://lists.trolltech.com/mailman/listinfo/qt-interest
>    >>
>    >> --
>    >> Jake Colman | Director, Software Development
>    >> Principia Partners LLC
>    >> 101 West Elm Street | Conshohocken | PA 19428 | +1 (610) 755
9770
>    >> t: +1 (610) 755 9786 | c: +1 (610) 348 2788 | f: +1 (201) 221
8929
>    >> e: colman at ppllc.com | w: www.principiapartners.com
>    >> Credit technology innovation awards winner 2008
>    >>
>    >> _______________________________________________
>    >> Qt-interest mailing list
>    >> Qt-interest at trolltech.com
>    >> http://lists.trolltech.com/mailman/listinfo/qt-interest
> 
> --
> Jake Colman | Director, Software Development
> Principia Partners LLC
> 101 West Elm Street | Conshohocken | PA 19428 | +1 (610) 755 9770
> t: +1 (610) 755 9786 | c: +1 (610) 348 2788 | f: +1 (201) 221 8929
> e: colman at ppllc.com | w: www.principiapartners.com
> Credit technology innovation awards winner 2008




More information about the Qt-interest-old mailing list