<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html><head><title>QSpinBox Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm } a:link { color: #004faf; text-decoration: none } a:visited { color: #672967; text-decoration: none } td.postheader { font-family: sans-serif } tr.address { font-family: sans-serif } body { background: #ffffff; color: black; } </style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">  </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QSpinBox Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QSpinBox class provides a spin box widget. <a href="#details">More...</a></p> <p>Inherits <a href="qabstractspinbox.html">QAbstractSpinBox</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qspinbox.html#QSpinBox">__init__</a></b> (<i>self</i>, QWidget <i>parent</i> = None)</li><li><div class="fn" />QString <b><a href="qspinbox.html#cleanText">cleanText</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qspinbox.html#event">event</a></b> (<i>self</i>, QEvent <i>e</i>)</li><li><div class="fn" />QString <i>str</i> <b><a href="qspinbox.html#fixup">fixup</a></b> (<i>self</i>, QString <i>str</i>)</li><li><div class="fn" /><b><a href="qspinbox.html#fixup-2">fixup</a></b> (<i>self</i>, QString <i>str</i>)</li><li><div class="fn" />int <b><a href="qspinbox.html#maximum">maximum</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qspinbox.html#minimum">minimum</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qspinbox.html#prefix">prefix</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qspinbox.html#setMaximum">setMaximum</a></b> (<i>self</i>, int <i>max</i>)</li><li><div class="fn" /><b><a href="qspinbox.html#setMinimum">setMinimum</a></b> (<i>self</i>, int <i>min</i>)</li><li><div class="fn" /><b><a href="qspinbox.html#setPrefix">setPrefix</a></b> (<i>self</i>, QString <i>p</i>)</li><li><div class="fn" /><b><a href="qspinbox.html#setRange">setRange</a></b> (<i>self</i>, int <i>min</i>, int <i>max</i>)</li><li><div class="fn" /><b><a href="qspinbox.html#setSingleStep">setSingleStep</a></b> (<i>self</i>, int <i>val</i>)</li><li><div class="fn" /><b><a href="qspinbox.html#setSuffix">setSuffix</a></b> (<i>self</i>, QString <i>s</i>)</li><li><div class="fn" /><b><a href="qspinbox.html#setValue">setValue</a></b> (<i>self</i>, int <i>val</i>)</li><li><div class="fn" />int <b><a href="qspinbox.html#singleStep">singleStep</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qspinbox.html#suffix">suffix</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qspinbox.html#textFromValue">textFromValue</a></b> (<i>self</i>, int <i>v</i>)</li><li><div class="fn" />(QValidator.State, QString <i>input</i>, int <i>pos</i>) <b><a href="qspinbox.html#validate">validate</a></b> (<i>self</i>, QString <i>input</i>, int <i>pos</i>)</li><li><div class="fn" />(QValidator.State, int <i>pos</i>) <b><a href="qspinbox.html#validate-2">validate</a></b> (<i>self</i>, QString <i>input</i>, int <i>pos</i>)</li><li><div class="fn" />int <b><a href="qspinbox.html#value">value</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qspinbox.html#valueFromText">valueFromText</a></b> (<i>self</i>, QString <i>text</i>)</li></ul><h3>Qt Signals</h3><ul><li><div class="fn" />void <b><a href="qspinbox.html#valueChanged">valueChanged</a></b> (int)</li><li><div class="fn" />void <b><a href="qspinbox.html#valueChanged-2">valueChanged</a></b> (const QString&)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QSpinBox class provides a spin box widget.</p> <p>QSpinBox is designed to handle integers and discrete sets of values (e.g., month names); use <a href="qdoublespinbox.html">QDoubleSpinBox</a> for floating point values.</p> <p>QSpinBox allows the user to choose a value by clicking the up/down buttons or pressing up/down on the keyboard to increase/decrease the value currently displayed. The user can also type the value in manually. The spin box supports integer values but can be extended to use different strings with <a href="qspinbox.html#validate">validate</a>(), <a href="qspinbox.html#textFromValue">textFromValue</a>() and <a href="qspinbox.html#valueFromText">valueFromText</a>().</p> <p>Every time the value changes QSpinBox emits the <a href="qspinbox.html#valueChanged">valueChanged</a>() signals. The current value can be fetched with <a href="qspinbox.html#value-prop">value</a>() and set with <a href="qspinbox.html#value-prop">setValue</a>().</p> <p>Clicking the up/down buttons or using the keyboard accelerator's up and down arrows will increase or decrease the current value in steps of size <a href="qspinbox.html#singleStep-prop">singleStep</a>(). If you want to change this behaviour you can reimplement the virtual function <a href="qabstractspinbox.html#stepBy">stepBy</a>(). The minimum and maximum value and the step size can be set using one of the constructors, and can be changed later with <a href="qspinbox.html#minimum-prop">setMinimum</a>(), <a href="qspinbox.html#maximum-prop">setMaximum</a>() and <a href="qspinbox.html#singleStep-prop">setSingleStep</a>().</p> <p>Most spin boxes are directional, but QSpinBox can also operate as a circular spin box, i.e. if the range is 0-99 and the current value is 99, clicking "up" will give 0 if <a href="qabstractspinbox.html#wrapping-prop">wrapping</a>() is set to true. Use <a href="qabstractspinbox.html#wrapping-prop">setWrapping</a>() if you want circular behavior.</p> <p>The displayed value can be prepended and appended with arbitrary strings indicating, for example, currency or the unit of measurement. See <a href="qspinbox.html#prefix-prop">setPrefix</a>() and <a href="qspinbox.html#suffix-prop">setSuffix</a>(). The text in the spin box is retrieved with <a href="qabstractspinbox.html#text-prop">text</a>() (which includes any <a href="qspinbox.html#prefix-prop">prefix</a>() and <a href="qspinbox.html#suffix-prop">suffix</a>()), or with <a href="qspinbox.html#cleanText-prop">cleanText</a>() (which has no <a href="qspinbox.html#prefix-prop">prefix</a>(), no <a href="qspinbox.html#suffix-prop">suffix</a>() and no leading or trailing whitespace).</p> <p>It is often desirable to give the user a special (often default) choice in addition to the range of numeric values. See <a href="qabstractspinbox.html#specialValueText-prop">setSpecialValueText</a>() for how to do this with QSpinBox.</p> <table class="generic" width="100%"> <tr class="odd" valign="top"> <td><img alt="Screenshot of a Windows XP spin box" src="images/windowsxp-spinbox.png" /></td> <td>A spin box shown in the <a href="gallery-windowsxp.html">Windows XP widget style</a>.</td> </tr> <tr class="even" valign="top"> <td><img alt="Screenshot of a Plastique spin box" src="images/plastique-spinbox.png" /></td> <td>A spin box shown in the <a href="gallery-plastique.html">Plastique widget style</a>.</td> </tr> <tr class="odd" valign="top"> <td><img alt="Screenshot of a Macintosh spin box" src="images/macintosh-spinbox.png" /></td> <td>A spin box shown in the <a href="gallery-macintosh.html">Macintosh widget style</a>.</td> </tr> </table> <a id="subclassing-qspinbox" name="subclassing-qspinbox" /> <h3>Subclassing QSpinBox</h3> <p>If using <a href="qspinbox.html#prefix-prop">prefix</a>(), <a href="qspinbox.html#suffix-prop">suffix</a>(), and <a href="qabstractspinbox.html#specialValueText-prop">specialValueText</a>() don't provide enough control, you subclass QSpinBox and reimplement <a href="qspinbox.html#valueFromText">valueFromText</a>() and <a href="qspinbox.html#textFromValue">textFromValue</a>(). For example, here's the code for a custom spin box that allows the user to enter icon sizes (e.g., "32 x 32"):</p> <pre class="cpp"> <span class="type">int</span> IconSizeSpinBox<span class="operator">.</span><a href="qspinbox.html#valueFromText">valueFromText</a>(<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&</span>text) <span class="keyword">const</span> { <span class="type"><a href="qregexp.html">QRegExp</a></span> regExp(tr(<span class="string">"(\\d+)(\\s*[xx]\\s*\\d+)?"</span>)); <span class="keyword">if</span> (regExp<span class="operator">.</span>exactMatch(text)) { <span class="keyword">return</span> regExp<span class="operator">.</span>cap(<span class="number">1</span>)<span class="operator">.</span>toInt(); } <span class="keyword">else</span> { <span class="keyword">return</span> <span class="number">0</span>; } } <span class="type"><a href="qstring.html">QString</a></span> IconSizeSpinBox<span class="operator">.</span><a href="qspinbox.html#textFromValue">textFromValue</a>(<span class="type">int</span> value) <span class="keyword">const</span> { <span class="keyword">return</span> tr(<span class="string">"%1 x %1"</span>)<span class="operator">.</span>arg(value); } </pre> <p>See the <a href="widgets-icons.html">Icons</a> example for the full source code.</p> <hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QSpinBox" />QSpinBox.__init__ (<i>self</i>, <a href="qwidget.html">QWidget</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a spin box with 0 as minimum value and 99 as maximum value, a step value of 1. The value is initially set to 0. It is parented to <i>parent</i>.</p> <p><b>See also</b> <a href="qspinbox.html#minimum-prop">setMinimum</a>(), <a href="qspinbox.html#maximum-prop">setMaximum</a>(), and <a href="qspinbox.html#singleStep-prop">setSingleStep</a>().</p> <h3 class="fn"><a name="cleanText" />QString QSpinBox.cleanText (<i>self</i>)</h3><h3 class="fn"><a name="event" />bool QSpinBox.event (<i>self</i>, <a href="qevent.html">QEvent</a> <i>e</i>)</h3><p>Reimplemented from <a href="qobject.html#event">QObject.event</a>().</p> <h3 class="fn"><a name="fixup" />QString <i>str</i> QSpinBox.fixup (<i>self</i>, QString <i>str</i>)</h3><p>Reimplemented from <a href="qabstractspinbox.html#fixup">QAbstractSpinBox.fixup</a>().</p> <h3 class="fn"><a name="fixup-2" />QSpinBox.fixup (<i>self</i>, QString <i>str</i>)</h3><h3 class="fn"><a name="maximum" />int QSpinBox.maximum (<i>self</i>)</h3><h3 class="fn"><a name="minimum" />int QSpinBox.minimum (<i>self</i>)</h3><h3 class="fn"><a name="prefix" />QString QSpinBox.prefix (<i>self</i>)</h3><h3 class="fn"><a name="setMaximum" />QSpinBox.setMaximum (<i>self</i>, int <i>max</i>)</h3><h3 class="fn"><a name="setMinimum" />QSpinBox.setMinimum (<i>self</i>, int <i>min</i>)</h3><h3 class="fn"><a name="setPrefix" />QSpinBox.setPrefix (<i>self</i>, QString <i>p</i>)</h3><h3 class="fn"><a name="setRange" />QSpinBox.setRange (<i>self</i>, int <i>min</i>, int <i>max</i>)</h3><p>Convenience function to set the <i>minimum</i>, and <i>maximum</i> values with a single function call.</p> <pre class="cpp"> setRange(minimum<span class="operator">,</span> maximum); </pre> <p>is equivalent to:</p> <pre class="cpp"> <a href="qspinbox.html#minimum-prop">setMinimum</a>(minimum); <a href="qspinbox.html#maximum-prop">setMaximum</a>(maximum); </pre> <p><b>See also</b> <a href="qspinbox.html#minimum-prop">minimum</a> and <a href="qspinbox.html#maximum-prop">maximum</a>.</p> <h3 class="fn"><a name="setSingleStep" />QSpinBox.setSingleStep (<i>self</i>, int <i>val</i>)</h3><h3 class="fn"><a name="setSuffix" />QSpinBox.setSuffix (<i>self</i>, QString <i>s</i>)</h3><h3 class="fn"><a name="setValue" />QSpinBox.setValue (<i>self</i>, int <i>val</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void setValue(int)</tt>.</p><h3 class="fn"><a name="singleStep" />int QSpinBox.singleStep (<i>self</i>)</h3><h3 class="fn"><a name="suffix" />QString QSpinBox.suffix (<i>self</i>)</h3><h3 class="fn"><a name="textFromValue" />QString QSpinBox.textFromValue (<i>self</i>, int <i>v</i>)</h3><p>This virtual function is used by the spin box whenever it needs to display the given <i>value</i>. The default implementation returns a string containing <i>value</i> printed in the standard way using <a href="qwidget.html#locale-prop">QWidget.locale</a>().toString(), but with the thousand separator removed. Reimplementations may return anything. (See the example in the detailed description.)</p> <p>Note: <a href="qspinbox.html">QSpinBox</a> does not call this function for <a href="qabstractspinbox.html#specialValueText-prop">specialValueText</a>() and that neither <a href="qspinbox.html#prefix-prop">prefix</a>() nor <a href="qspinbox.html#suffix-prop">suffix</a>() should be included in the return value.</p> <p>If you reimplement this, you may also need to reimplement <a href="qspinbox.html#valueFromText">valueFromText</a>() and <a href="qspinbox.html#validate">validate</a>()</p> <p><b>See also</b> <a href="qspinbox.html#valueFromText">valueFromText</a>(), <a href="qspinbox.html#validate">validate</a>(), and <a href="qlocale.html#groupSeparator">QLocale.groupSeparator</a>().</p> <h3 class="fn"><a name="validate" />(<a href="qvalidator.html#State-enum">QValidator.State</a>, QString <i>input</i>, int <i>pos</i>) QSpinBox.validate (<i>self</i>, QString <i>input</i>, int <i>pos</i>)</h3><p>Reimplemented from <a href="qabstractspinbox.html#validate">QAbstractSpinBox.validate</a>().</p> <h3 class="fn"><a name="validate-2" />(<a href="qvalidator.html#State-enum">QValidator.State</a>, int <i>pos</i>) QSpinBox.validate (<i>self</i>, QString <i>input</i>, int <i>pos</i>)</h3><h3 class="fn"><a name="value" />int QSpinBox.value (<i>self</i>)</h3><h3 class="fn"><a name="valueFromText" />int QSpinBox.valueFromText (<i>self</i>, QString <i>text</i>)</h3><p>This virtual function is used by the spin box whenever it needs to interpret <i>text</i> entered by the user as a value.</p> <p>Subclasses that need to display spin box values in a non-numeric way need to reimplement this function.</p> <p>Note: <a href="qspinbox.html">QSpinBox</a> handles <a href="qabstractspinbox.html#specialValueText-prop">specialValueText</a>() separately; this function is only concerned with the other values.</p> <p><b>See also</b> <a href="qspinbox.html#textFromValue">textFromValue</a>() and <a href="qspinbox.html#validate">validate</a>().</p> <hr /><h2>Qt Signal Documentation</h2><h3 class="fn"><a name="valueChanged" />void valueChanged (int)</h3><p>This is the default overload of this signal.</p><p>This signal is emitted whenever the spin box's value is changed. The new value's integer value is passed in <i>i</i>.</p> <h3 class="fn"><a name="valueChanged-2" />void valueChanged (const QString&)</h3><p>This is an overloaded function.</p> <p>The new value is passed literally in <i>text</i> with no <a href="qspinbox.html#prefix-prop">prefix</a>() or <a href="qspinbox.html#suffix-prop">suffix</a>().</p> <address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.10.3 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt 4.8.5</td></tr></table></div></address></body></html>