Sophie

Sophie

distrib > Mageia > 7 > aarch64 > by-pkgid > 1dd17e0d683ef79b4bb6872bbf359d7f > files > 8030

qt4-doc-4.8.7-26.2.mga7.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" />
<!-- spinboxes.qdoc -->
  <title>Qt 4.8: Spin Boxes 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>Spin Boxes 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">Spin Boxes Example</h1>
<span class="subtitle"></span>
<!-- $$$widgets/spinboxes-description -->
<div class="descr"> <a name="details"></a>
<p>Files:</p>
<ul>
<li><a href="widgets-spinboxes-window-cpp.html">widgets/spinboxes/window.cpp</a></li>
<li><a href="widgets-spinboxes-window-h.html">widgets/spinboxes/window.h</a></li>
<li><a href="widgets-spinboxes-main-cpp.html">widgets/spinboxes/main.cpp</a></li>
<li><a href="widgets-spinboxes-spinboxes-pro.html">widgets/spinboxes/spinboxes.pro</a></li>
</ul>
<p>The Spin Boxes example shows how to use the many different types of spin boxes available in Qt, from a simple <a href="qspinbox.html">QSpinBox</a> widget to more complex editors like the <a href="qdatetimeedit.html">QDateTimeEdit</a> widget.<p class="centerAlign"><img src="images/spinboxes-example.png" alt="" /></p><p>The example consists of a single <tt>Window</tt> class that is used to display the different spin box-based widgets available with Qt.</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 two slots that are used to provide interactive features:</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> changePrecision(<span class="type">int</span> decimals);
     <span class="type">void</span> setFormatString(<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>formatString);

 <span class="keyword">private</span>:
     <span class="type">void</span> createSpinBoxes();
     <span class="type">void</span> createDateTimeEdits();
     <span class="type">void</span> createDoubleSpinBoxes();

     <span class="type"><a href="qdatetimeedit.html">QDateTimeEdit</a></span> <span class="operator">*</span>meetingEdit;
     <span class="type"><a href="qdoublespinbox.html">QDoubleSpinBox</a></span> <span class="operator">*</span>doubleSpinBox;
     <span class="type"><a href="qdoublespinbox.html">QDoubleSpinBox</a></span> <span class="operator">*</span>priceSpinBox;
     <span class="type"><a href="qdoublespinbox.html">QDoubleSpinBox</a></span> <span class="operator">*</span>scaleSpinBox;
     <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> <span class="operator">*</span>spinBoxesGroup;
     <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> <span class="operator">*</span>editsGroup;
     <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> <span class="operator">*</span>doubleSpinBoxesGroup;
     <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>meetingLabel;
 };</pre>
<p>The private functions are used to set up each type of spin box in the window. We use member variables to keep track of various widgets so that they can be reconfigured when required.</p>
<a name="window-class-implementation"></a>
<h2>Window Class Implementation</h2>
<p>The constructor simply calls private functions to set up the different types of spin box used in the example, and places each group in a layout:</p>
<pre class="cpp"> Window<span class="operator">::</span>Window()
 {
     createSpinBoxes();
     createDateTimeEdits();
     createDoubleSpinBoxes();

     <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>;
     layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(spinBoxesGroup);
     layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(editsGroup);
     layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(doubleSpinBoxesGroup);
     setLayout(layout);

     setWindowTitle(tr(<span class="string">&quot;Spin Boxes&quot;</span>));
 }</pre>
<p>We use the layout to manage the arrangement of the window's child widgets, and change the window title.</p>
<p>The <tt>createSpinBoxes()</tt> function constructs a <a href="qgroupbox.html">QGroupBox</a> and places three <a href="qspinbox.html">QSpinBox</a> widgets inside it with descriptive labels to indicate the types of input they expect.</p>
<pre class="cpp"> <span class="type">void</span> Window<span class="operator">::</span>createSpinBoxes()
 {
     spinBoxesGroup <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(tr(<span class="string">&quot;Spinboxes&quot;</span>));

     <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>integerLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Enter a value between &quot;</span>
         <span class="string">&quot;%1 and %2:&quot;</span>)<span class="operator">.</span>arg(<span class="operator">-</span><span class="number">20</span>)<span class="operator">.</span>arg(<span class="number">20</span>));
     <span class="type"><a href="qspinbox.html">QSpinBox</a></span> <span class="operator">*</span>integerSpinBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qspinbox.html">QSpinBox</a></span>;
     integerSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setRange(<span class="operator">-</span><span class="number">20</span><span class="operator">,</span> <span class="number">20</span>);
     integerSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setSingleStep(<span class="number">1</span>);
     integerSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setValue(<span class="number">0</span>);</pre>
<p>The first spin box shows the simplest way to use <a href="qspinbox.html">QSpinBox</a>. It accepts values from -20 to 20, the current value can be increased or decreased by 1 with either the arrow buttons or <b>Up</b> and <b>Down</b> keys, and the default value is 0.</p>
<p>The second spin box uses a larger step size and displays a suffix to provide more information about the type of data the number represents:</p>
<pre class="cpp">     <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>zoomLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Enter a zoom value between &quot;</span>
         <span class="string">&quot;%1 and %2:&quot;</span>)<span class="operator">.</span>arg(<span class="number">0</span>)<span class="operator">.</span>arg(<span class="number">1000</span>));
     <span class="type"><a href="qspinbox.html">QSpinBox</a></span> <span class="operator">*</span>zoomSpinBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qspinbox.html">QSpinBox</a></span>;
     zoomSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setRange(<span class="number">0</span><span class="operator">,</span> <span class="number">1000</span>);
     zoomSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setSingleStep(<span class="number">10</span>);
     zoomSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setSuffix(<span class="string">&quot;%&quot;</span>);
     zoomSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setSpecialValueText(tr(<span class="string">&quot;Automatic&quot;</span>));
     zoomSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setValue(<span class="number">100</span>);</pre>
<p>This spin box also displays a <a href="qabstractspinbox.html#specialValueText-prop">special value</a> instead of the minimum value defined for it. This means that it will never show <b>0%</b>, but will display <b>Automatic</b> when the minimum value is selected.</p>
<p>The third spin box shows how a prefix can be used:</p>
<pre class="cpp">     <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>priceLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Enter a price between &quot;</span>
         <span class="string">&quot;%1 and %2:&quot;</span>)<span class="operator">.</span>arg(<span class="number">0</span>)<span class="operator">.</span>arg(<span class="number">999</span>));
     <span class="type"><a href="qspinbox.html">QSpinBox</a></span> <span class="operator">*</span>priceSpinBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qspinbox.html">QSpinBox</a></span>;
     priceSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setRange(<span class="number">0</span><span class="operator">,</span> <span class="number">999</span>);
     priceSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setSingleStep(<span class="number">1</span>);
     priceSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setPrefix(<span class="string">&quot;$&quot;</span>);
     priceSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setValue(<span class="number">99</span>);</pre>
<p>For simplicity, we show a spin box with a prefix and no suffix. It is also possible to use both at the same time.</p>
<pre class="cpp">     <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>spinBoxLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>;
     spinBoxLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(integerLabel);
     spinBoxLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(integerSpinBox);
     spinBoxLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(zoomLabel);
     spinBoxLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(zoomSpinBox);
     spinBoxLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(priceLabel);
     spinBoxLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(priceSpinBox);
     spinBoxesGroup<span class="operator">-</span><span class="operator">&gt;</span>setLayout(spinBoxLayout);
 }</pre>
<p>The rest of the function sets up a layout for the group box and places each of the widgets inside it.</p>
<p>The <tt>createDateTimeEdits()</tt> function constructs another group box with a selection of spin boxes used for editing dates and times.</p>
<pre class="cpp"> <span class="type">void</span> Window<span class="operator">::</span>createDateTimeEdits()
 {
     editsGroup <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(tr(<span class="string">&quot;Date and time spin boxes&quot;</span>));

     <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>dateLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>;
     <span class="type"><a href="qdateedit.html">QDateEdit</a></span> <span class="operator">*</span>dateEdit <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qdateedit.html">QDateEdit</a></span>(<span class="type"><a href="qdate.html">QDate</a></span><span class="operator">::</span>currentDate());
     dateEdit<span class="operator">-</span><span class="operator">&gt;</span>setDateRange(<span class="type"><a href="qdate.html">QDate</a></span>(<span class="number">2005</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">1</span>)<span class="operator">,</span> <span class="type"><a href="qdate.html">QDate</a></span>(<span class="number">2010</span><span class="operator">,</span> <span class="number">12</span><span class="operator">,</span> <span class="number">31</span>));
     dateLabel<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Appointment date (between %0 and %1):&quot;</span>)
                        <span class="operator">.</span>arg(dateEdit<span class="operator">-</span><span class="operator">&gt;</span>minimumDate()<span class="operator">.</span>toString(<span class="type"><a href="qt.html">Qt</a></span><span class="operator">::</span>ISODate))
                        <span class="operator">.</span>arg(dateEdit<span class="operator">-</span><span class="operator">&gt;</span>maximumDate()<span class="operator">.</span>toString(<span class="type"><a href="qt.html">Qt</a></span><span class="operator">::</span>ISODate)));</pre>
<p>The first spin box is a <a href="qdateedit.html">QDateEdit</a> widget that is able to accept dates within a given range specified using <a href="qdate.html">QDate</a> values. The arrow buttons and <b>Up</b> and <b>Down</b> keys can be used to increase and decrease the values for year, month, and day when the cursor is in the relevant section.</p>
<p>The second spin box is a <a href="qtimeedit.html">QTimeEdit</a> widget:</p>
<pre class="cpp">     <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>timeLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>;
     <span class="type"><a href="qtimeedit.html">QTimeEdit</a></span> <span class="operator">*</span>timeEdit <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtimeedit.html">QTimeEdit</a></span>(<span class="type"><a href="qtime.html">QTime</a></span><span class="operator">::</span>currentTime());
     timeEdit<span class="operator">-</span><span class="operator">&gt;</span>setTimeRange(<span class="type"><a href="qtime.html">QTime</a></span>(<span class="number">9</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>)<span class="operator">,</span> <span class="type"><a href="qtime.html">QTime</a></span>(<span class="number">16</span><span class="operator">,</span> <span class="number">30</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>));
     timeLabel<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Appointment time (between %0 and %1):&quot;</span>)
                        <span class="operator">.</span>arg(timeEdit<span class="operator">-</span><span class="operator">&gt;</span>minimumTime()<span class="operator">.</span>toString(<span class="type"><a href="qt.html">Qt</a></span><span class="operator">::</span>ISODate))
                        <span class="operator">.</span>arg(timeEdit<span class="operator">-</span><span class="operator">&gt;</span>maximumTime()<span class="operator">.</span>toString(<span class="type"><a href="qt.html">Qt</a></span><span class="operator">::</span>ISODate)));</pre>
<p>Acceptable values for the time are defined using <a href="qtime.html">QTime</a> values.</p>
<p>The third spin box is a <a href="qdatetimeedit.html">QDateTimeEdit</a> widget that can display both date and time values, and we place a label above it to indicate the range of allowed times for a meeting. These widgets will be updated when the user changes a format string.</p>
<pre class="cpp">     meetingLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>;
     meetingEdit <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qdatetimeedit.html">QDateTimeEdit</a></span>(<span class="type"><a href="qdatetime.html">QDateTime</a></span><span class="operator">::</span>currentDateTime());</pre>
<p>The format string used for the date time editor, which is also shown in the string displayed by the label, is chosen from a set of strings in a combobox:</p>
<pre class="cpp">     <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>formatLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Format string for the meeting date &quot;</span>
                                         <span class="string">&quot;and time:&quot;</span>));
     <span class="type"><a href="qcombobox.html">QComboBox</a></span> <span class="operator">*</span>formatComboBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcombobox.html">QComboBox</a></span>;
     formatComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(<span class="string">&quot;yyyy-MM-dd hh:mm:ss (zzz 'ms')&quot;</span>);
     formatComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(<span class="string">&quot;hh:mm:ss MM/dd/yyyy&quot;</span>);
     formatComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(<span class="string">&quot;hh:mm:ss dd/MM/yyyy&quot;</span>);
     formatComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(<span class="string">&quot;hh:mm:ss&quot;</span>);
     formatComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(<span class="string">&quot;hh:mm ap&quot;</span>);

     connect(formatComboBox<span class="operator">,</span> SIGNAL(activated(<span class="type"><a href="qstring.html">QString</a></span>))<span class="operator">,</span>
             <span class="keyword">this</span><span class="operator">,</span> SLOT(setFormatString(<span class="type"><a href="qstring.html">QString</a></span>)));</pre>
<p>A signal from this combobox is connected to a slot in the <tt>Window</tt> class (shown later).</p>
<pre class="cpp">     <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>editsLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>;
     editsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(dateLabel);
     editsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(dateEdit);
     editsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(timeLabel);
     editsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(timeEdit);
     editsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(meetingLabel);
     editsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(meetingEdit);
     editsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(formatLabel);
     editsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(formatComboBox);
     editsGroup<span class="operator">-</span><span class="operator">&gt;</span>setLayout(editsLayout);
 }</pre>
<p>Each child widget of the group box in placed in a layout.</p>
<p>The <tt>setFormatString()</tt> slot is called whenever the user selects a new format string in the combobox. The display format for the <a href="qdatetimeedit.html">QDateTimeEdit</a> widget is set using the raw string passed by the signal:</p>
<pre class="cpp"> <span class="type">void</span> Window<span class="operator">::</span>setFormatString(<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>formatString)
 {
     meetingEdit<span class="operator">-</span><span class="operator">&gt;</span>setDisplayFormat(formatString);</pre>
<p>Depending on the visible sections in the widget, we set a new date or time range, and update the associated label to provide relevant information for the user:</p>
<pre class="cpp">     <span class="keyword">if</span> (meetingEdit<span class="operator">-</span><span class="operator">&gt;</span>displayedSections() <span class="operator">&amp;</span> <span class="type"><a href="qdatetimeedit.html">QDateTimeEdit</a></span><span class="operator">::</span>DateSections_Mask) {
         meetingEdit<span class="operator">-</span><span class="operator">&gt;</span>setDateRange(<span class="type"><a href="qdate.html">QDate</a></span>(<span class="number">2004</span><span class="operator">,</span> <span class="number">11</span><span class="operator">,</span> <span class="number">1</span>)<span class="operator">,</span> <span class="type"><a href="qdate.html">QDate</a></span>(<span class="number">2005</span><span class="operator">,</span> <span class="number">11</span><span class="operator">,</span> <span class="number">30</span>));
         meetingLabel<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Meeting date (between %0 and %1):&quot;</span>)
             <span class="operator">.</span>arg(meetingEdit<span class="operator">-</span><span class="operator">&gt;</span>minimumDate()<span class="operator">.</span>toString(<span class="type"><a href="qt.html">Qt</a></span><span class="operator">::</span>ISODate))
             <span class="operator">.</span>arg(meetingEdit<span class="operator">-</span><span class="operator">&gt;</span>maximumDate()<span class="operator">.</span>toString(<span class="type"><a href="qt.html">Qt</a></span><span class="operator">::</span>ISODate)));
     } <span class="keyword">else</span> {
         meetingEdit<span class="operator">-</span><span class="operator">&gt;</span>setTimeRange(<span class="type"><a href="qtime.html">QTime</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">7</span><span class="operator">,</span> <span class="number">20</span><span class="operator">,</span> <span class="number">0</span>)<span class="operator">,</span> <span class="type"><a href="qtime.html">QTime</a></span>(<span class="number">21</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>));
         meetingLabel<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Meeting time (between %0 and %1):&quot;</span>)
             <span class="operator">.</span>arg(meetingEdit<span class="operator">-</span><span class="operator">&gt;</span>minimumTime()<span class="operator">.</span>toString(<span class="type"><a href="qt.html">Qt</a></span><span class="operator">::</span>ISODate))
             <span class="operator">.</span>arg(meetingEdit<span class="operator">-</span><span class="operator">&gt;</span>maximumTime()<span class="operator">.</span>toString(<span class="type"><a href="qt.html">Qt</a></span><span class="operator">::</span>ISODate)));
     }
 }</pre>
<p>When the format string is changed, there will be an appropriate label and entry widget for dates, times, or both types of input.</p>
<p>The <tt>createDoubleSpinBoxes()</tt> function constructs three spin boxes that are used to input double-precision floating point numbers:</p>
<pre class="cpp"> <span class="type">void</span> Window<span class="operator">::</span>createDoubleSpinBoxes()
 {
     doubleSpinBoxesGroup <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(tr(<span class="string">&quot;Double precision spinboxes&quot;</span>));

     <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>precisionLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Number of decimal places &quot;</span>
                                            <span class="string">&quot;to show:&quot;</span>));
     <span class="type"><a href="qspinbox.html">QSpinBox</a></span> <span class="operator">*</span>precisionSpinBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qspinbox.html">QSpinBox</a></span>;
     precisionSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setRange(<span class="number">0</span><span class="operator">,</span> <span class="number">100</span>);
     precisionSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setValue(<span class="number">2</span>);</pre>
<p>Before the <a href="qdoublespinbox.html">QDoubleSpinBox</a> widgets are constructed, we create a spin box to control how many decimal places they show. By default, only two decimal places are shown in the following spin boxes, each of which is the equivalent of a spin box in the group created by the <tt>createSpinBoxes()</tt> function.</p>
<p>The first double spin box shows a basic double-precision spin box with the same range, step size, and default value as the first spin box in the <tt>createSpinBoxes()</tt> function:</p>
<pre class="cpp">     <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>doubleLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Enter a value between &quot;</span>
         <span class="string">&quot;%1 and %2:&quot;</span>)<span class="operator">.</span>arg(<span class="operator">-</span><span class="number">20</span>)<span class="operator">.</span>arg(<span class="number">20</span>));
     doubleSpinBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qdoublespinbox.html">QDoubleSpinBox</a></span>;
     doubleSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setRange(<span class="operator">-</span><span class="number">20.0</span><span class="operator">,</span> <span class="number">20.0</span>);
     doubleSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setSingleStep(<span class="number">1.0</span>);
     doubleSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setValue(<span class="number">0.0</span>);</pre>
<p>However, this spin box also allows non-integer values to be entered.</p>
<p>The second spin box displays a suffix and shows a special value instead of the minimum value:</p>
<pre class="cpp">     <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>scaleLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Enter a scale factor between &quot;</span>
         <span class="string">&quot;%1 and %2:&quot;</span>)<span class="operator">.</span>arg(<span class="number">0</span>)<span class="operator">.</span>arg(<span class="number">1000.0</span>));
     scaleSpinBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qdoublespinbox.html">QDoubleSpinBox</a></span>;
     scaleSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setRange(<span class="number">0.0</span><span class="operator">,</span> <span class="number">1000.0</span>);
     scaleSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setSingleStep(<span class="number">10.0</span>);
     scaleSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setSuffix(<span class="string">&quot;%&quot;</span>);
     scaleSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setSpecialValueText(tr(<span class="string">&quot;No scaling&quot;</span>));
     scaleSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setValue(<span class="number">100.0</span>);</pre>
<p>The third spin box displays a prefix instead of a suffix:</p>
<pre class="cpp">     <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>priceLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Enter a price between &quot;</span>
         <span class="string">&quot;%1 and %2:&quot;</span>)<span class="operator">.</span>arg(<span class="number">0</span>)<span class="operator">.</span>arg(<span class="number">1000</span>));
     priceSpinBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qdoublespinbox.html">QDoubleSpinBox</a></span>;
     priceSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setRange(<span class="number">0.0</span><span class="operator">,</span> <span class="number">1000.0</span>);
     priceSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setSingleStep(<span class="number">1.0</span>);
     priceSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setPrefix(<span class="string">&quot;$&quot;</span>);
     priceSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setValue(<span class="number">99.99</span>);

     connect(precisionSpinBox<span class="operator">,</span> SIGNAL(valueChanged(<span class="type">int</span>))<span class="operator">,</span></pre>
<p>We connect the <a href="qspinbox.html">QSpinBox</a> widget that specifies the precision to a slot in the <tt>Window</tt> class.</p>
<pre class="cpp">     <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>spinBoxLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>;
     spinBoxLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(precisionLabel);
     spinBoxLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(precisionSpinBox);
     spinBoxLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(doubleLabel);
     spinBoxLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(doubleSpinBox);
     spinBoxLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(scaleLabel);
     spinBoxLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(scaleSpinBox);
     spinBoxLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(priceLabel);
     spinBoxLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(priceSpinBox);
     doubleSpinBoxesGroup<span class="operator">-</span><span class="operator">&gt;</span>setLayout(spinBoxLayout);
 }</pre>
<p>The rest of the function places each of the widgets into a layout for the group box.</p>
<p>The <tt>changePrecision()</tt> slot is called when the user changes the value in the precision spin box:</p>
<pre class="cpp"> <span class="type">void</span> Window<span class="operator">::</span>changePrecision(<span class="type">int</span> decimals)
 {
     doubleSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setDecimals(decimals);
     scaleSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setDecimals(decimals);
     priceSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setDecimals(decimals);
 }</pre>
<p>This function simply uses the integer supplied by the signal to specify the number of decimal places in each of the <a href="qdoublespinbox.html">QDoubleSpinBox</a> widgets. Each one of these will be updated automatically when their <a href="qdoublespinbox.html#decimals-prop">decimals</a> property is changed.</p>
</div>
<!-- @@@widgets/spinboxes -->
      </div>
    </div>
    </div> 
    <div class="ft">
      <span></span>
    </div>
  </div> 
  <div class="footer">
    <p>
      <acronym title="Copyright">&copy;</acronym> 2015 The Qt Company Ltd.
      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>
      Qt and respective logos are trademarks of The Qt Company Ltd 
      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>