[Qt-interest] Help getting out of Gridlayout Hell

Jake Colman colman at ppllc.com
Wed Apr 29 04:40:24 CEST 2009


Scott,

Hmmm.  I thought I tried that but will try it again.

The comboboxes are all specified to be the same size.  The labels are
all of varying sizes.  You are suggesting that I get the max of minimum
size hint since that is the minimums size required to display the
longest label.  I should set every label's minimum size (using
setMinimumSize() method) to the output of the size() method?

...Jake


>>>>> "SAB" == Scott Aron Bloom <Scott.Bloom at sabgroup.com> writes:

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

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

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

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

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

   SAB> 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
   SAB> 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
   SAB> group
   >> box
   SAB> B with a sub layout of type vertical.
   SAB> Setting each of their margins to the same value, will have
   SAB> 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
   SAB> 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
   SAB> two
   >> >> independent group boxes that have exactly the same alignment?
   SAB> Remember
   >> >> that a groupbox uses an internal gridlayout.  The size of each
   SAB> cell in
   >> >> the grid depends on the cell's contents.  Two independent
   SAB> groupboxes
   >> >> with independent gridlayout may end up with different sizing.
   SAB> How do
   >> >> you make it consistent?
   >> >>
   >> >>
   >> >> >>>>> "SAB" == Scott Aron Bloom <Scott.Bloom at sabgroup.com>
   SAB> 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
   SAB> grid.
   SAB> This
   SAB> is
   >> >> >> normally nice and simple.  The problem is that I need to use
   SAB> a
   SAB> groupbox
   >> >> >> to group some of the widgets in this grid.  The problem is
   SAB> 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
   SAB> 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
   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

-- 
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