Sophie

Sophie

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

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" />
<!-- lineedits.qdoc -->
  <title>Qt 4.8: Line Edits 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>Line Edits 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="#window-class-definition">Window Class Definition</a></li>
<li class="level1"><a href="#window-class-implementation">Window Class Implementation</a></li>
</ul>
</div>
<h1 class="title">Line Edits Example</h1>
<span class="subtitle"></span>
<!-- $$$widgets/lineedits-description -->
<div class="descr"> <a name="details"></a>
<p>Files:</p>
<ul>
<li><a href="widgets-lineedits-window-cpp.html">widgets/lineedits/window.cpp</a></li>
<li><a href="widgets-lineedits-window-h.html">widgets/lineedits/window.h</a></li>
<li><a href="widgets-lineedits-main-cpp.html">widgets/lineedits/main.cpp</a></li>
<li><a href="widgets-lineedits-lineedits-pro.html">widgets/lineedits/lineedits.pro</a></li>
</ul>
<p>The Line Edits example demonstrates the many ways that <a href="qlineedit.html">QLineEdit</a> can be used, and shows the effects of various properties and validators on the input and output supplied by the user.<p class="centerAlign"><img src="images/lineedits-example.png" alt="" /></p><p>The example consists of a single <tt>Window</tt> class, containing a selection of line edits with different input constraints and display properties that can be changed by selecting items from comboboxes. Presenting these together helps developers choose suitable properties to use with line edits, and makes it easy to compare the effects of each validator on user input.</p>
<a name="window-class-definition"></a>
<h2>Window Class Definition</h2>
<p>The <tt>Window</tt> class inherits <a href="qwidget.html">QWidget</a> and contains a constructor and several slots:</p>
<pre class="cpp"> <span class="keyword">class</span> Window : <span class="keyword">public</span> <span class="type"><a href="qwidget.html">QWidget</a></span>
 {
     Q_OBJECT

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

 <span class="keyword">public</span> <span class="keyword">slots</span>:
     <span class="type">void</span> echoChanged(<span class="type">int</span>);
     <span class="type">void</span> validatorChanged(<span class="type">int</span>);
     <span class="type">void</span> alignmentChanged(<span class="type">int</span>);
     <span class="type">void</span> inputMaskChanged(<span class="type">int</span>);
     <span class="type">void</span> accessChanged(<span class="type">int</span>);

 <span class="keyword">private</span>:
     <span class="type"><a href="qlineedit.html">QLineEdit</a></span> <span class="operator">*</span>echoLineEdit;
     <span class="type"><a href="qlineedit.html">QLineEdit</a></span> <span class="operator">*</span>validatorLineEdit;
     <span class="type"><a href="qlineedit.html">QLineEdit</a></span> <span class="operator">*</span>alignmentLineEdit;
     <span class="type"><a href="qlineedit.html">QLineEdit</a></span> <span class="operator">*</span>inputMaskLineEdit;
     <span class="type"><a href="qlineedit.html">QLineEdit</a></span> <span class="operator">*</span>accessLineEdit;
 };</pre>
<p>The slots are used to update the type of validator used for a given line edit when a new validator has been selected in the associated combobox. The line edits are stored in the window for use in these slots.</p>
<a name="window-class-implementation"></a>
<h2>Window Class Implementation</h2>
<p>The <tt>Window</tt> constructor is used to set up the line edits, validators, and comboboxes, connect signals from the comboboxes to slots in the <tt>Window</tt> class, and arrange the child widgets in layouts.</p>
<p>We begin by constructing a <a href="qgroupbox.html">group box</a> to hold a label, combobox, and line edit so that we can demonstrate the <a href="qlineedit.html#echoMode-prop">QLineEdit::echoMode</a> property:</p>
<pre class="cpp"> Window<span class="operator">::</span>Window()
 {
     <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> <span class="operator">*</span>echoGroup <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(tr(<span class="string">&quot;Echo&quot;</span>));

     <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>echoLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Mode:&quot;</span>));
     <span class="type"><a href="qcombobox.html">QComboBox</a></span> <span class="operator">*</span>echoComboBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcombobox.html">QComboBox</a></span>;
     echoComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;Normal&quot;</span>));
     echoComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;Password&quot;</span>));
     echoComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;PasswordEchoOnEdit&quot;</span>));
     echoComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;No Echo&quot;</span>));

     echoLineEdit <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlineedit.html">QLineEdit</a></span>;
     echoLineEdit<span class="operator">-</span><span class="operator">&gt;</span>setFocus();</pre>
<p>At this point, none of these widgets have been arranged in layouts. Eventually, the <tt>echoLabel</tt>, <tt>echoComboBox</tt>, and <tt>echoLineEdit</tt> will be placed in a vertical layout inside the <tt>echoGroup</tt> group box.</p>
<p>Similarly, we construct group boxes and collections of widgets to show the effects of <a href="qintvalidator.html">QIntValidator</a> and <a href="qdoublevalidator.html">QDoubleValidator</a> on a line edit's contents:</p>
<pre class="cpp">     <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> <span class="operator">*</span>validatorGroup <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(tr(<span class="string">&quot;Validator&quot;</span>));

     <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>validatorLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Type:&quot;</span>));
     <span class="type"><a href="qcombobox.html">QComboBox</a></span> <span class="operator">*</span>validatorComboBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcombobox.html">QComboBox</a></span>;
     validatorComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;No validator&quot;</span>));
     validatorComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;Integer validator&quot;</span>));
     validatorComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;Double validator&quot;</span>));

     validatorLineEdit <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlineedit.html">QLineEdit</a></span>;</pre>
<p>Text alignment is demonstrated by another group of widgets:</p>
<pre class="cpp">     <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> <span class="operator">*</span>alignmentGroup <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(tr(<span class="string">&quot;Alignment&quot;</span>));

     <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>alignmentLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Type:&quot;</span>));
     <span class="type"><a href="qcombobox.html">QComboBox</a></span> <span class="operator">*</span>alignmentComboBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcombobox.html">QComboBox</a></span>;
     alignmentComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;Left&quot;</span>));
     alignmentComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;Centered&quot;</span>));
     alignmentComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;Right&quot;</span>));

     alignmentLineEdit <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlineedit.html">QLineEdit</a></span>;</pre>
<p><a href="qlineedit.html">QLineEdit</a> supports the use of <a href="qlineedit.html#inputMask-prop">input masks</a>. These only allow the user to type characters into the line edit that follow a simple specification. We construct a group of widgets to demonstrate a selection of predefined masks:</p>
<pre class="cpp">     <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> <span class="operator">*</span>inputMaskGroup <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(tr(<span class="string">&quot;Input mask&quot;</span>));

     <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>inputMaskLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Type:&quot;</span>));
     <span class="type"><a href="qcombobox.html">QComboBox</a></span> <span class="operator">*</span>inputMaskComboBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcombobox.html">QComboBox</a></span>;
     inputMaskComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;No mask&quot;</span>));
     inputMaskComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;Phone number&quot;</span>));
     inputMaskComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;ISO date&quot;</span>));
     inputMaskComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;License key&quot;</span>));

     inputMaskLineEdit <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlineedit.html">QLineEdit</a></span>;</pre>
<p>Another useful feature of <a href="qlineedit.html">QLineEdit</a> is its ability to make its contents read-only. This property is used to control access to a line edit in the following group of widgets:</p>
<pre class="cpp">     <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> <span class="operator">*</span>accessGroup <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(tr(<span class="string">&quot;Access&quot;</span>));

     <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>accessLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Read-only:&quot;</span>));
     <span class="type"><a href="qcombobox.html">QComboBox</a></span> <span class="operator">*</span>accessComboBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcombobox.html">QComboBox</a></span>;
     accessComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;False&quot;</span>));
     accessComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;True&quot;</span>));

     accessLineEdit <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlineedit.html">QLineEdit</a></span>;</pre>
<p>Now that all the child widgets have been constructed, we connect signals from the comboboxes to slots in the <tt>Window</tt> object:</p>
<pre class="cpp">     connect(echoComboBox<span class="operator">,</span> SIGNAL(activated(<span class="type">int</span>))<span class="operator">,</span>
             <span class="keyword">this</span><span class="operator">,</span> SLOT(echoChanged(<span class="type">int</span>)));
     connect(validatorComboBox<span class="operator">,</span> SIGNAL(activated(<span class="type">int</span>))<span class="operator">,</span>
             <span class="keyword">this</span><span class="operator">,</span> SLOT(validatorChanged(<span class="type">int</span>)));
     connect(alignmentComboBox<span class="operator">,</span> SIGNAL(activated(<span class="type">int</span>))<span class="operator">,</span>
             <span class="keyword">this</span><span class="operator">,</span> SLOT(alignmentChanged(<span class="type">int</span>)));
     connect(inputMaskComboBox<span class="operator">,</span> SIGNAL(activated(<span class="type">int</span>))<span class="operator">,</span>
             <span class="keyword">this</span><span class="operator">,</span> SLOT(inputMaskChanged(<span class="type">int</span>)));
     connect(accessComboBox<span class="operator">,</span> SIGNAL(activated(<span class="type">int</span>))<span class="operator">,</span>
             <span class="keyword">this</span><span class="operator">,</span> SLOT(accessChanged(<span class="type">int</span>)));</pre>
<p>Each of these connections use the <a href="qcombobox.html#activated">QComboBox::activated</a>() signal that supplies an integer to the slot. This will be used to efficiently make changes to the appropriate line edit in each slot.</p>
<p>We place each combobox, line edit, and label in a layout for each group box, beginning with the layout for the <tt>echoGroup</tt> group box:</p>
<pre class="cpp">     <span class="type"><a href="qgridlayout.html">QGridLayout</a></span> <span class="operator">*</span>echoLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgridlayout.html">QGridLayout</a></span>;
     echoLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(echoLabel<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>);
     echoLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(echoComboBox<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span>);
     echoLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(echoLineEdit<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">2</span>);
     echoGroup<span class="operator">-</span><span class="operator">&gt;</span>setLayout(echoLayout);</pre>
<p>The other layouts are constructed in the same way:</p>
<pre class="cpp">     <span class="type"><a href="qgridlayout.html">QGridLayout</a></span> <span class="operator">*</span>validatorLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgridlayout.html">QGridLayout</a></span>;
     validatorLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(validatorLabel<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>);
     validatorLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(validatorComboBox<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span>);
     validatorLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(validatorLineEdit<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">2</span>);
     validatorGroup<span class="operator">-</span><span class="operator">&gt;</span>setLayout(validatorLayout);

     <span class="type"><a href="qgridlayout.html">QGridLayout</a></span> <span class="operator">*</span>alignmentLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgridlayout.html">QGridLayout</a></span>;
     alignmentLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(alignmentLabel<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>);
     alignmentLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(alignmentComboBox<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span>);
     alignmentLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(alignmentLineEdit<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">2</span>);
     alignmentGroup<span class="operator">-</span><span class="operator">&gt;</span> setLayout(alignmentLayout);

     <span class="type"><a href="qgridlayout.html">QGridLayout</a></span> <span class="operator">*</span>inputMaskLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgridlayout.html">QGridLayout</a></span>;
     inputMaskLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(inputMaskLabel<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>);
     inputMaskLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(inputMaskComboBox<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span>);
     inputMaskLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(inputMaskLineEdit<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">2</span>);
     inputMaskGroup<span class="operator">-</span><span class="operator">&gt;</span>setLayout(inputMaskLayout);

     <span class="type"><a href="qgridlayout.html">QGridLayout</a></span> <span class="operator">*</span>accessLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgridlayout.html">QGridLayout</a></span>;
     accessLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(accessLabel<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>);
     accessLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(accessComboBox<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span>);
     accessLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(accessLineEdit<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">2</span>);
     accessGroup<span class="operator">-</span><span class="operator">&gt;</span>setLayout(accessLayout);</pre>
<p>Finally, we place each group box in a grid layout for the <tt>Window</tt> object and set the window title:</p>
<pre class="cpp">     <span class="type"><a href="qgridlayout.html">QGridLayout</a></span> <span class="operator">*</span>layout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgridlayout.html">QGridLayout</a></span>;
     layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(echoGroup<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>);
     layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(validatorGroup<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(alignmentGroup<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">0</span>);
     layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(inputMaskGroup<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span>);
     layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(accessGroup<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">1</span>);
     setLayout(layout);

     setWindowTitle(tr(<span class="string">&quot;Line Edits&quot;</span>));
 }</pre>
<p>The slots respond to signals emitted when the comboboxes are changed by the user.</p>
<p>When the combobox for the <b>Echo</b> group box is changed, the <tt>echoChanged()</tt> slot is called:</p>
<pre class="cpp"> <span class="type">void</span> Window<span class="operator">::</span>echoChanged(<span class="type">int</span> index)
 {
     <span class="keyword">switch</span> (index) {
     <span class="keyword">case</span> <span class="number">0</span>:
         echoLineEdit<span class="operator">-</span><span class="operator">&gt;</span>setEchoMode(<span class="type"><a href="qlineedit.html">QLineEdit</a></span><span class="operator">::</span>Normal);
         <span class="keyword">break</span>;
     <span class="keyword">case</span> <span class="number">1</span>:
         echoLineEdit<span class="operator">-</span><span class="operator">&gt;</span>setEchoMode(<span class="type"><a href="qlineedit.html">QLineEdit</a></span><span class="operator">::</span>Password);
         <span class="keyword">break</span>;
     <span class="keyword">case</span> <span class="number">2</span>:
         echoLineEdit<span class="operator">-</span><span class="operator">&gt;</span>setEchoMode(<span class="type"><a href="qlineedit.html">QLineEdit</a></span><span class="operator">::</span>PasswordEchoOnEdit);
         <span class="keyword">break</span>;
     <span class="keyword">case</span> <span class="number">3</span>:
         echoLineEdit<span class="operator">-</span><span class="operator">&gt;</span>setEchoMode(<span class="type"><a href="qlineedit.html">QLineEdit</a></span><span class="operator">::</span>NoEcho);
     }
 }</pre>
<p>The slot updates the line edit in the same group box to use an echo mode that corresponds to the entry described in the combobox.</p>
<p>When the combobox for the <b>Validator</b> group box is changed, the <tt>validatorChanged()</tt> slot is called:</p>
<pre class="cpp"> <span class="type">void</span> Window<span class="operator">::</span>validatorChanged(<span class="type">int</span> index)
 {
     <span class="keyword">switch</span> (index) {
     <span class="keyword">case</span> <span class="number">0</span>:
         validatorLineEdit<span class="operator">-</span><span class="operator">&gt;</span>setValidator(<span class="number">0</span>);
         <span class="keyword">break</span>;
     <span class="keyword">case</span> <span class="number">1</span>:
         validatorLineEdit<span class="operator">-</span><span class="operator">&gt;</span>setValidator(<span class="keyword">new</span> <span class="type"><a href="qintvalidator.html">QIntValidator</a></span>(
             validatorLineEdit));
         <span class="keyword">break</span>;
     <span class="keyword">case</span> <span class="number">2</span>:
         validatorLineEdit<span class="operator">-</span><span class="operator">&gt;</span>setValidator(<span class="keyword">new</span> <span class="type"><a href="qdoublevalidator.html">QDoubleValidator</a></span>(<span class="operator">-</span><span class="number">999.0</span><span class="operator">,</span>
             <span class="number">999.0</span><span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> validatorLineEdit));
     }

     validatorLineEdit<span class="operator">-</span><span class="operator">&gt;</span>clear();
 }</pre>
<p>The slot either creates a new validator for the line edit to use, or it removes the validator in use by calling <a href="qlineedit.html#setValidator">QLineEdit::setValidator</a>() with a zero pointer. We clear the line edit in this case to ensure that the new validator is initially given valid input to work with.</p>
<p>When the combobox for the <b>Alignment</b> group box is changed, the <tt>alignmentChanged()</tt> slot is called:</p>
<pre class="cpp"> <span class="type">void</span> Window<span class="operator">::</span>alignmentChanged(<span class="type">int</span> index)
 {
     <span class="keyword">switch</span> (index) {
     <span class="keyword">case</span> <span class="number">0</span>:
         alignmentLineEdit<span class="operator">-</span><span class="operator">&gt;</span>setAlignment(<span class="type"><a href="qt.html">Qt</a></span><span class="operator">::</span>AlignLeft);
         <span class="keyword">break</span>;
     <span class="keyword">case</span> <span class="number">1</span>:
         alignmentLineEdit<span class="operator">-</span><span class="operator">&gt;</span>setAlignment(<span class="type"><a href="qt.html">Qt</a></span><span class="operator">::</span>AlignCenter);
         <span class="keyword">break</span>;
     <span class="keyword">case</span> <span class="number">2</span>:
         alignmentLineEdit<span class="operator">-</span><span class="operator">&gt;</span>setAlignment(<span class="type"><a href="qt.html">Qt</a></span><span class="operator">::</span>AlignRight);
     }
 }</pre>
<p>This changes the way that text is displayed in the line edit to correspond with the description selected in the combobox.</p>
<p>The <tt>inputMaskChanged()</tt> slot handles changes to the combobox in the <b>Input Mask</b> group box:</p>
<pre class="cpp"> <span class="type">void</span> Window<span class="operator">::</span>inputMaskChanged(<span class="type">int</span> index)
 {
     <span class="keyword">switch</span> (index) {
     <span class="keyword">case</span> <span class="number">0</span>:
         inputMaskLineEdit<span class="operator">-</span><span class="operator">&gt;</span>setInputMask(<span class="string">&quot;&quot;</span>);
         <span class="keyword">break</span>;
     <span class="keyword">case</span> <span class="number">1</span>:
         inputMaskLineEdit<span class="operator">-</span><span class="operator">&gt;</span>setInputMask(<span class="string">&quot;+99 99 99 99 99;_&quot;</span>);
         <span class="keyword">break</span>;
     <span class="keyword">case</span> <span class="number">2</span>:
         inputMaskLineEdit<span class="operator">-</span><span class="operator">&gt;</span>setInputMask(<span class="string">&quot;0000-00-00&quot;</span>);
         inputMaskLineEdit<span class="operator">-</span><span class="operator">&gt;</span>setText(<span class="string">&quot;00000000&quot;</span>);
         inputMaskLineEdit<span class="operator">-</span><span class="operator">&gt;</span>setCursorPosition(<span class="number">0</span>);
         <span class="keyword">break</span>;
     <span class="keyword">case</span> <span class="number">3</span>:
         inputMaskLineEdit<span class="operator">-</span><span class="operator">&gt;</span>setInputMask(<span class="string">&quot;&gt;AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#&quot;</span>);
     }
 }</pre>
<p>Each entry in the relevant combobox is associated with an input mask. We set a new mask by calling the <a href="qwidget.html#setMask">QLineEdit::setMask</a>() function with a suitable string; the mask is disabled if an empty string is used.</p>
<p>The <tt>accessChanged()</tt> slot handles changes to the combobox in the <b>Access</b> group box:</p>
<pre class="cpp"> <span class="type">void</span> Window<span class="operator">::</span>accessChanged(<span class="type">int</span> index)
 {
     <span class="keyword">switch</span> (index) {
     <span class="keyword">case</span> <span class="number">0</span>:
         accessLineEdit<span class="operator">-</span><span class="operator">&gt;</span>setReadOnly(<span class="keyword">false</span>);
         <span class="keyword">break</span>;
     <span class="keyword">case</span> <span class="number">1</span>:
         accessLineEdit<span class="operator">-</span><span class="operator">&gt;</span>setReadOnly(<span class="keyword">true</span>);
     }
 }</pre>
<p>Here, we simply associate the <b>False</b> and <b>True</b> entries in the combobox with <tt>false</tt> and <tt>true</tt> values to be passed to <a href="qlineedit.html#readOnly-prop">QLineEdit::setReadOnly</a>(). This allows the user to enable and disable input to the line edit.</p>
</div>
<!-- @@@widgets/lineedits -->
      </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>