Sophie

Sophie

distrib > Fedora > 18 > x86_64 > by-pkgid > ff187cb994c94c614ecc64c5a8528b1b > files > 3906

qt-doc-4.8.5-10.fc18.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- basiclayouts.qdoc -->
  <title>Qt 4.8: Basic Layouts Example</title>
  <link rel="stylesheet" type="text/css" href="style/style.css" />
  <script src="scripts/jquery.js" type="text/javascript"></script>
  <script src="scripts/functions.js" type="text/javascript"></script>
  <link rel="stylesheet" type="text/css" href="style/superfish.css" />
  <link rel="stylesheet" type="text/css" href="style/narrow.css" />
  <!--[if IE]>
<meta name="MSSmartTagsPreventParsing" content="true">
<meta http-equiv="imagetoolbar" content="no">
<![endif]-->
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie6.css">
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie7.css">
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="style/style_ie8.css">
<![endif]-->

<script src="scripts/superfish.js" type="text/javascript"></script>
<script src="scripts/narrow.js" type="text/javascript"></script>

</head>
<body class="" onload="CheckEmptyAndLoadList();">
 <div class="header" id="qtdocheader">
    <div class="content"> 
    <div id="nav-logo">
      <a href="index.html">Home</a></div>
    <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
    <div id="narrowsearch"></div>
    <div id="nav-topright">
      <ul>
        <li class="nav-topright-home"><a href="http://qt.digia.com/">Qt HOME</a></li>
        <li class="nav-topright-dev"><a href="http://qt-project.org/">DEV</a></li>
        <li class="nav-topright-doc nav-topright-doc-active"><a href="http://qt-project.org/doc/">
          DOC</a></li>
        <li class="nav-topright-blog"><a href="http://blog.qt.digia.com/">BLOG</a></li>
      </ul>
    </div>
    <div id="shortCut">
      <ul>
        <li class="shortCut-topleft-inactive"><span><a href="index.html">Qt 4.8</a></span></li>
        <li class="shortCut-topleft-active"><a href="http://qt-project.org/doc/">ALL VERSIONS        </a></li>
      </ul>
     </div>
 <ul class="sf-menu" id="narrowmenu"> 
             <li><a href="#">API Lookup</a> 
                 <ul> 
                     <li><a href="classes.html">Class index</a></li> 
           <li><a href="functions.html">Function index</a></li> 
           <li><a href="modules.html">Modules</a></li> 
           <li><a href="namespaces.html">Namespaces</a></li> 
           <li><a href="qtglobal.html">Global Declarations</a></li> 
           <li><a href="qdeclarativeelements.html">QML elements</a></li> 
             </ul> 
             </li> 
             <li><a href="#">Qt Topics</a> 
                 <ul> 
                        <li><a href="qt-basic-concepts.html">Programming with Qt</a></li>  
                        <li><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li>  
                        <li><a href="qt-gui-concepts.html">UI Design with Qt</a></li>  
                        <li><a href="supported-platforms.html">Supported Platforms</a></li>  
                        <li><a href="technology-apis.html">Qt and Key Technologies</a></li>  
                        <li><a href="best-practices.html">How-To's and Best Practices</a></li>  
              </ul> 
                 </li> 
                 <li><a href="#">Examples</a> 
                     <ul> 
                       <li><a href="all-examples.html">Examples</a></li> 
                       <li><a href="tutorials.html">Tutorials</a></li> 
                       <li><a href="demos.html">Demos</a></li> 
                       <li><a href="qdeclarativeexamples.html">QML Examples</a></li> 
                </ul> 
                     </li> 
                 </ul> 
    </div>
  </div>
  <div class="wrapper">
    <div class="hd">
      <span></span>
    </div>
    <div class="bd group">
      <div class="sidebar">
        <div class="searchlabel">
          Search index:</div>
        <div class="search" id="sidebarsearch">
          <form id="qtdocsearch" action="" onsubmit="return false;">
            <fieldset>
              <input type="text" name="searchstring" id="pageType" value="" />
 <div id="resultdialog"> 
 <a href="#" id="resultclose">Close</a> 
 <p id="resultlinks" class="all"><a href="#" id="showallresults">All</a> | <a href="#" id="showapiresults">API</a> | <a href="#" id="showarticleresults">Articles</a> | <a href="#" id="showexampleresults">Examples</a></p> 
 <p id="searchcount" class="all"><span id="resultcount"></span><span id="apicount"></span><span id="articlecount"></span><span id="examplecount"></span>&nbsp;results:</p> 
 <ul id="resultlist" class="all"> 
 </ul> 
 </div> 
            </fieldset>
          </form>
        </div>
        <div class="box first bottombar" id="lookup">
          <h2 title="API Lookup"><span></span>
            API Lookup</h2>
          <div  id="list001" class="list">
          <ul id="ul001" >
              <li class="defaultLink"><a href="classes.html">Class index</a></li>
              <li class="defaultLink"><a href="functions.html">Function index</a></li>
              <li class="defaultLink"><a href="modules.html">Modules</a></li>
              <li class="defaultLink"><a href="namespaces.html">Namespaces</a></li>
              <li class="defaultLink"><a href="qtglobal.html">Global Declarations</a></li>
              <li class="defaultLink"><a href="qdeclarativeelements.html">QML elements</a></li>
            </ul> 
          </div>
        </div>
        <div class="box bottombar" id="topics">
          <h2 title="Qt Topics"><span></span>
            Qt Topics</h2>
          <div id="list002" class="list">
            <ul id="ul002" >
               <li class="defaultLink"><a href="qt-basic-concepts.html">Programming with Qt</a></li> 
               <li class="defaultLink"><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li> 
               <li class="defaultLink"><a href="qt-gui-concepts.html">UI Design with Qt</a></li> 
               <li class="defaultLink"><a href="supported-platforms.html">Supported Platforms</a></li>  
               <li class="defaultLink"><a href="technology-apis.html">Qt and Key Technologies</a></li> 
               <li class="defaultLink"><a href="best-practices.html">How-To's and Best Practices</a></li> 
            </ul>  
          </div>
        </div>
        <div class="box" id="examples">
          <h2 title="Examples"><span></span>
            Examples</h2>
          <div id="list003" class="list">
        <ul id="ul003">
              <li class="defaultLink"><a href="all-examples.html">Examples</a></li>
              <li class="defaultLink"><a href="tutorials.html">Tutorials</a></li>
              <li class="defaultLink"><a href="demos.html">Demos</a></li>
              <li class="defaultLink"><a href="qdeclarativeexamples.html">QML Examples</a></li>
            </ul> 
          </div>
        </div>
      </div>
      <div class="wrap">
        <div class="toolbar">
          <div class="breadcrumb toolblock">
            <ul>
              <li class="first"><a href="index.html">Home</a></li>
              <!--  Breadcrumbs go here -->
<li><a href="all-examples.html">Examples</a></li>
<li>Basic Layouts Example</li>
            </ul>
          </div>
          <div class="toolbuttons toolblock">
            <ul>
              <li id="smallA" class="t_button">A</li>
              <li id="medA" class="t_button active">A</li>
              <li id="bigA" class="t_button">A</li>
              <li id="print" class="t_button"><a href="javascript:this.print();">
                <span>Print</span></a></li>
            </ul>
        </div>
        </div>
        <div class="content mainContent">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#dialog-class-definition">Dialog Class Definition</a></li>
<li class="level1"><a href="#dialog-class-implementation">Dialog Class Implementation</a></li>
</ul>
</div>
<h1 class="title">Basic Layouts Example</h1>
<span class="subtitle"></span>
<!-- $$$layouts/basiclayouts-description -->
<div class="descr"> <a name="details"></a>
<p>Files:</p>
<ul>
<li><a href="layouts-basiclayouts-dialog-cpp.html">layouts/basiclayouts/dialog.cpp</a></li>
<li><a href="layouts-basiclayouts-dialog-h.html">layouts/basiclayouts/dialog.h</a></li>
<li><a href="layouts-basiclayouts-main-cpp.html">layouts/basiclayouts/main.cpp</a></li>
<li><a href="layouts-basiclayouts-basiclayouts-pro.html">layouts/basiclayouts/basiclayouts.pro</a></li>
</ul>
<p>The Basic Layouts example shows how to use the standard layout managers that are available in Qt: <a href="qboxlayout.html">QBoxLayout</a>, <a href="qgridlayout.html">QGridLayout</a> and <a href="qformlayout.html">QFormLayout</a>.<p class="centerAlign"><img src="images/basiclayouts-example.png" alt="Screenshot of the Basic Layouts example" /></p><p>The <a href="qboxlayout.html">QBoxLayout</a> class lines up widgets horizontally or vertically. <a href="qhboxlayout.html">QHBoxLayout</a> and <a href="qvboxlayout.html">QVBoxLayout</a> are convenience subclasses of <a href="qboxlayout.html">QBoxLayout</a>. <a href="qgridlayout.html">QGridLayout</a> lays out widgets in cells by dividing the available space into rows and columns. <a href="qformlayout.html">QFormLayout</a>, on the other hand, lays out its children in a two-column form with labels in the left column and input fields in the right column.</p>
<a name="dialog-class-definition"></a>
<h2>Dialog Class Definition</h2>
<pre class="cpp"> <span class="keyword">class</span> Dialog : <span class="keyword">public</span> <span class="type"><a href="qdialog.html">QDialog</a></span>
 {
     Q_OBJECT

 <span class="keyword">public</span>:
     Dialog();

 <span class="keyword">private</span>:
     <span class="type">void</span> createMenu();
     <span class="type">void</span> createHorizontalGroupBox();
     <span class="type">void</span> createGridGroupBox();
     <span class="type">void</span> createFormGroupBox();

     <span class="keyword">enum</span> { NumGridRows <span class="operator">=</span> <span class="number">3</span><span class="operator">,</span> NumButtons <span class="operator">=</span> <span class="number">4</span> };

     <span class="type"><a href="qmenubar.html">QMenuBar</a></span> <span class="operator">*</span>menuBar;
     <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> <span class="operator">*</span>horizontalGroupBox;
     <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> <span class="operator">*</span>gridGroupBox;
     <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> <span class="operator">*</span>formGroupBox;
     <span class="type"><a href="qtextedit.html">QTextEdit</a></span> <span class="operator">*</span>smallEditor;
     <span class="type"><a href="qtextedit.html">QTextEdit</a></span> <span class="operator">*</span>bigEditor;
     <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>labels<span class="operator">[</span>NumGridRows<span class="operator">]</span>;
     <span class="type"><a href="qlineedit.html">QLineEdit</a></span> <span class="operator">*</span>lineEdits<span class="operator">[</span>NumGridRows<span class="operator">]</span>;
     <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>buttons<span class="operator">[</span>NumButtons<span class="operator">]</span>;
     <span class="type"><a href="qdialogbuttonbox.html">QDialogButtonBox</a></span> <span class="operator">*</span>buttonBox;

     <span class="type"><a href="qmenu.html">QMenu</a></span> <span class="operator">*</span>fileMenu;
     <span class="type"><a href="qaction.html">QAction</a></span> <span class="operator">*</span>exitAction;
 };</pre>
<p>The <tt>Dialog</tt> class inherits <a href="qdialog.html">QDialog</a>. It is a custom widget that displays its child widgets using the geometry managers: <a href="qhboxlayout.html">QHBoxLayout</a>, <a href="qvboxlayout.html">QVBoxLayout</a>, <a href="qgridlayout.html">QGridLayout</a> and <a href="qformlayout.html">QFormLayout</a>.</p>
<p>We declare four private functions to simplify the class constructor: The <tt>createMenu()</tt>, <tt>createHorizontalGroupBox()</tt>, <tt>createGridGroupBox()</tt> and <tt>createFormGroupBox()</tt> functions create several widgets that the example uses to demonstrate how the layout affects their appearances.</p>
<a name="dialog-class-implementation"></a>
<h2>Dialog Class Implementation</h2>
<pre class="cpp"> Dialog<span class="operator">::</span>Dialog()
 {
     createMenu();
     createHorizontalGroupBox();
     createGridGroupBox();
     createFormGroupBox();</pre>
<p>In the constructor, we first use the <tt>createMenu()</tt> function to create and populate a menu bar and the <tt>createHorizontalGroupBox()</tt> function to create a group box containing four buttons with a horizontal layout. Next we use the <tt>createGridGroupBox()</tt> function to create a group box containing several line edits and a small text editor which are displayed in a grid layout. Finally, we use the <tt>createFormGroupBox()</tt> function to create a group box with three labels and three input fields: a line edit, a combo box and a spin box.</p>
<pre class="cpp">     bigEditor <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtextedit.html">QTextEdit</a></span>;
     bigEditor<span class="operator">-</span><span class="operator">&gt;</span>setPlainText(tr(<span class="string">&quot;This widget takes up all the remaining space &quot;</span>
                                <span class="string">&quot;in the top-level layout.&quot;</span>));

     buttonBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qdialogbuttonbox.html">QDialogButtonBox</a></span>(<span class="type"><a href="qdialogbuttonbox.html">QDialogButtonBox</a></span><span class="operator">::</span>Ok
                                      <span class="operator">|</span> <span class="type"><a href="qdialogbuttonbox.html">QDialogButtonBox</a></span><span class="operator">::</span>Cancel);

     connect(buttonBox<span class="operator">,</span> SIGNAL(accepted())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(accept()));
     connect(buttonBox<span class="operator">,</span> SIGNAL(rejected())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(reject()));</pre>
<p>We also create a big text editor and a dialog button box. The <a href="qdialogbuttonbox.html">QDialogButtonBox</a> class is a widget that presents buttons in a layout that is appropriate to the current widget style. The preferred buttons can be specified as arguments to the constructor, using the <a href="qdialogbuttonbox.html#StandardButton-enum">QDialogButtonBox::StandardButtons</a> enum.</p>
<p>Note that we don't have to specify a parent for the widgets when we create them. The reason is that all the widgets we create here will be added to a layout, and when we add a widget to a layout, it is automatically reparented to the widget the layout is installed on.</p>
<pre class="cpp">     <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>mainLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>;</pre>
<p>The main layout is a <a href="qvboxlayout.html">QVBoxLayout</a> object. <a href="qvboxlayout.html">QVBoxLayout</a> is a convenience class for a box layout with vertical orientation.</p>
<p>In general, the <a href="qboxlayout.html">QBoxLayout</a> class takes the space it gets (from its parent layout or from the parent widget), divides it up into a series of boxes, and makes each managed widget fill one box. If the <a href="qboxlayout.html">QBoxLayout</a>'s orientation is <a href="qt.html#Orientation-enum">Qt::Horizontal</a> the boxes are placed in a row. If the orientation is <a href="qt.html#Orientation-enum">Qt::Vertical</a>, the boxes are placed in a column. The corresponding convenience classes are <a href="qhboxlayout.html">QHBoxLayout</a> and <a href="qvboxlayout.html">QVBoxLayout</a>, respectively.</p>
<pre class="cpp">     mainLayout<span class="operator">-</span><span class="operator">&gt;</span>setMenuBar(menuBar);</pre>
<p>When we call the <a href="qlayout.html#setMenuBar">QLayout::setMenuBar</a>() function, the layout places the provided menu bar at the top of the parent widget, and outside the widget's <a href="qwidget.html#contentsRect">content margins</a>. All child widgets are placed below the bottom edge of the menu bar.</p>
<pre class="cpp">     mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(horizontalGroupBox);
     mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(gridGroupBox);
     mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(formGroupBox);
     mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(bigEditor);
     mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(buttonBox);</pre>
<p>We use the <a href="qboxlayout.html#addWidget">QBoxLayout::addWidget</a>() function to add the widgets to the end of layout. Each widget will get at least its minimum size and at most its maximum size. It is possible to specify a stretch factor in the <a href="qboxlayout.html#addWidget">addWidget()</a> function, and any excess space is shared according to these stretch factors. If not specified, a widget's stretch factor is 0.</p>
<pre class="cpp">     setLayout(mainLayout);

     setWindowTitle(tr(<span class="string">&quot;Basic Layouts&quot;</span>));
 }</pre>
<p>We install the main layout on the <tt>Dialog</tt> widget using the <a href="qwidget.html#setLayout">QWidget::setLayout</a>() function, and all of the layout's widgets are automatically reparented to be children of the <tt>Dialog</tt> widget.</p>
<pre class="cpp"> <span class="type">void</span> Dialog<span class="operator">::</span>createMenu()
 {
     menuBar <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qmenubar.html">QMenuBar</a></span>;

     fileMenu <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qmenu.html">QMenu</a></span>(tr(<span class="string">&quot;&amp;File&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);
     exitAction <span class="operator">=</span> fileMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(tr(<span class="string">&quot;E&amp;xit&quot;</span>));
     menuBar<span class="operator">-</span><span class="operator">&gt;</span>addMenu(fileMenu);

     connect(exitAction<span class="operator">,</span> SIGNAL(triggered())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(accept()));
 }</pre>
<p>In the private <tt>createMenu()</tt> function we create a menu bar, and add a pull-down <b>File</b> menu containing an <b>Exit</b> option.</p>
<pre class="cpp"> <span class="type">void</span> Dialog<span class="operator">::</span>createHorizontalGroupBox()
 {
     horizontalGroupBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(tr(<span class="string">&quot;Horizontal layout&quot;</span>));
     <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span> <span class="operator">*</span>layout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span>;

     <span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator">&lt;</span> NumButtons; <span class="operator">+</span><span class="operator">+</span>i) {
         buttons<span class="operator">[</span>i<span class="operator">]</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">&quot;Button %1&quot;</span>)<span class="operator">.</span>arg(i <span class="operator">+</span> <span class="number">1</span>));
         layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(buttons<span class="operator">[</span>i<span class="operator">]</span>);
     }
     horizontalGroupBox<span class="operator">-</span><span class="operator">&gt;</span>setLayout(layout);
 }</pre>
<p>When we create the horizontal group box, we use a <a href="qhboxlayout.html">QHBoxLayout</a> as the internal layout. We create the buttons we want to put in the group box, add them to the layout and install the layout on the group box.</p>
<pre class="cpp"> <span class="type">void</span> Dialog<span class="operator">::</span>createGridGroupBox()
 {
     gridGroupBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(tr(<span class="string">&quot;Grid layout&quot;</span>));</pre>
<p>In the <tt>createGridGroupBox()</tt> function we use a <a href="qgridlayout.html">QGridLayout</a> which lays out widgets in a grid. It takes the space made available to it (by its parent layout or by the parent widget), divides it up into rows and columns, and puts each widget it manages into the correct cell.</p>
<pre class="cpp">     <span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator">&lt;</span> NumGridRows; <span class="operator">+</span><span class="operator">+</span>i) {
         labels<span class="operator">[</span>i<span class="operator">]</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Line %1:&quot;</span>)<span class="operator">.</span>arg(i <span class="operator">+</span> <span class="number">1</span>));
         lineEdits<span class="operator">[</span>i<span class="operator">]</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlineedit.html">QLineEdit</a></span>;
         layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(labels<span class="operator">[</span>i<span class="operator">]</span><span class="operator">,</span> i <span class="operator">+</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span>);
         layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(lineEdits<span class="operator">[</span>i<span class="operator">]</span><span class="operator">,</span> i <span class="operator">+</span> <span class="number">1</span><span class="operator">,</span> <span class="number">1</span>);
     }</pre>
<p>For each row in the grid we create a label and an associated line edit, and add them to the layout. The <a href="qgridlayout.html#addWidget">QGridLayout::addWidget</a>() function differ from the corresponding function in <a href="qboxlayout.html">QBoxLayout</a>: It needs the row and column specifying the grid cell to put the widget in.</p>
<pre class="cpp">     smallEditor <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtextedit.html">QTextEdit</a></span>;
     smallEditor<span class="operator">-</span><span class="operator">&gt;</span>setPlainText(tr(<span class="string">&quot;This widget takes up about two thirds of the &quot;</span>
                                  <span class="string">&quot;grid layout.&quot;</span>));
     layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(smallEditor<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">4</span><span class="operator">,</span> <span class="number">1</span>);</pre>
<p><a href="qgridlayout.html#addWidget">QGridLayout::addWidget</a>() can in addition take arguments specifying the number of rows and columns the cell will be spanning. In this example, we create a small editor which spans three rows and one column.</p>
<p>For both the <a href="qboxlayout.html#addWidget">QBoxLayout::addWidget</a>() and <a href="qgridlayout.html#addWidget">QGridLayout::addWidget</a>() functions it is also possible to add a last argument specifying the widget's alignment. By default it fills the whole cell. But we could, for example, align a widget with the right edge by specifying the alignment to be <a href="qt.html#AlignmentFlag-enum">Qt::AlignRight</a>.</p>
<pre class="cpp">     layout<span class="operator">-</span><span class="operator">&gt;</span>setColumnStretch(<span class="number">1</span><span class="operator">,</span> <span class="number">10</span>);
     layout<span class="operator">-</span><span class="operator">&gt;</span>setColumnStretch(<span class="number">2</span><span class="operator">,</span> <span class="number">20</span>);
     gridGroupBox<span class="operator">-</span><span class="operator">&gt;</span>setLayout(layout);
 }</pre>
<p>Each column in a grid layout has a stretch factor. The stretch factor is set using <a href="qgridlayout.html#setColumnStretch">QGridLayout::setColumnStretch</a>() and determines how much of the available space the column will get over and above its necessary minimum.</p>
<p>In this example, we set the stretch factors for columns 1 and 2. The stretch factor is relative to the other columns in this grid; columns with a higher stretch factor take more of the available space. So column 2 in our grid layout will get more of the available space than column 1, and column 0 will not grow at all since its stretch factor is 0 (the default).</p>
<p>Columns and rows behave identically; there is an equivalent stretch factor for rows, as well as a <a href="qgridlayout.html#setRowStretch">QGridLayout::setRowStretch</a>() function.</p>
<pre class="cpp"> <span class="type">void</span> Dialog<span class="operator">::</span>createFormGroupBox()
 {
     formGroupBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(tr(<span class="string">&quot;Form layout&quot;</span>));
     <span class="type"><a href="qformlayout.html">QFormLayout</a></span> <span class="operator">*</span>layout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qformlayout.html">QFormLayout</a></span>;
     layout<span class="operator">-</span><span class="operator">&gt;</span>addRow(<span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Line 1:&quot;</span>))<span class="operator">,</span> <span class="keyword">new</span> <span class="type"><a href="qlineedit.html">QLineEdit</a></span>);
     layout<span class="operator">-</span><span class="operator">&gt;</span>addRow(<span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Line 2, long text:&quot;</span>))<span class="operator">,</span> <span class="keyword">new</span> <span class="type"><a href="qcombobox.html">QComboBox</a></span>);
     layout<span class="operator">-</span><span class="operator">&gt;</span>addRow(<span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Line 3:&quot;</span>))<span class="operator">,</span> <span class="keyword">new</span> <span class="type"><a href="qspinbox.html">QSpinBox</a></span>);
     formGroupBox<span class="operator">-</span><span class="operator">&gt;</span>setLayout(layout);
 }</pre>
<p>In the <tt>createFormGroupBox()</tt> function, we use a <a href="qformlayout.html">QFormLayout</a> to neatly arrange objects into two columns - name and field. There are three <a href="qlabel.html">QLabel</a> objects for names with three corresponding input widgets as fields: a <a href="qlineedit.html">QLineEdit</a>, a <a href="qcombobox.html">QComboBox</a> and a <a href="qspinbox.html">QSpinBox</a>. Unlike <a href="qboxlayout.html#addWidget">QBoxLayout::addWidget</a>() and <a href="qgridlayout.html#addWidget">QGridLayout::addWidget</a>(), we use <a href="qformlayout.html#addRow">QFormLayout::addRow</a>() to add widgets to the layout.</p>
</div>
<!-- @@@layouts/basiclayouts -->
      </div>
    </div>
    </div> 
    <div class="ft">
      <span></span>
    </div>
  </div> 
  <div class="footer">
    <p>
      <acronym title="Copyright">&copy;</acronym> 2013 Digia Plc and/or its
      subsidiaries. Documentation contributions included herein are the copyrights of
      their respective owners.</p>
    <br />
    <p>
      The documentation provided herein is licensed under the terms of the
      <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation
      License version 1.3</a> as published by the Free Software Foundation.</p>
    <p>
      Documentation sources may be obtained from <a href="http://www.qt-project.org">
      www.qt-project.org</a>.</p>
    <br />
    <p>
      Digia, Qt and their respective logos are trademarks of Digia Plc 
      in Finland and/or other countries worldwide. All other trademarks are property
      of their respective owners. <a title="Privacy Policy"
      href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
  </div>

  <script src="scripts/functions.js" type="text/javascript"></script>
</body>
</html>