1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
<?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="../pyqt4ref.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" /><b><a href="qspinbox.html#fixup">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, 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" />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. If the value is entered directly into the spin box, the value will be changed and <a href="qspinbox.html#valueChanged">valueChanged</a>() will be emitted with the new value when Enter/Return is pressed, when the spin box loses focus or when the spin box is deactivated (see QWidget.windowActivationChanged()). The spin box supports integer values but can be extended to use different strings with <a href="qabstractspinbox.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 align="center" border="0" cellpadding="2" cellspacing="1" width="100%">
<tr bgcolor="#F0F0F0" 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 bgcolor="#E0E0E0" 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 bgcolor="#F0F0F0" 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>
<br />
<br />
<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>
int IconSizeSpinBox.valueFromText(const QString &text) const
{
QRegExp regExp(tr("(\\d+)(\\s*[xx]\\s*\\d+)?"));
if (regExp.exactMatch(text)) {
return regExp.cap(1).toInt();
} else {
return 0;
}
}
QString IconSizeSpinBox.textFromValue(int value) const
{
return tr("%1 x %1").arg(value);
}
</pre>
<p>See the <a href="widgets-icons.html">Icons</a> example for the full source code.</p>
<p>See also <a href="qdoublespinbox.html">QDoubleSpinBox</a>, <a href="qslider.html">QSlider</a>, and <a href="guibooks.html#fowler">GUI Design Handbook: Slider</a>.</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>See also <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" /><a href="qstring.html">QString</a> 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><h3 class="fn"><a name="fixup" />QSpinBox.fixup (<i>self</i>, <a href="qstring.html">QString</a> <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" /><a href="qstring.html">QString</a> 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>, <a href="qstring.html">QString</a> <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 minimum, <i>min</i>, and maximum, <i>max</i>, values with a single function call.</p>
<pre>
setRange(min, max);
</pre>
<p>is equivalent to:</p>
<pre>
setMinimum(min);
setMaximum(max);
</pre>
<p>See also <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>, <a href="qstring.html">QString</a> <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" /><a href="qstring.html">QString</a> QSpinBox.suffix (<i>self</i>)</h3><h3 class="fn"><a name="textFromValue" /><a href="qstring.html">QString</a> 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 value <i>v</i>. The default implementation returns a string containing <i>v</i> printed in the standard way using QLocale().toString(v). 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="qabstractspinbox.html#validate">validate</a>()</p>
<p>See also <a href="qspinbox.html#valueFromText">valueFromText</a>() and <a href="qabstractspinbox.html#validate">validate</a>().</p>
<h3 class="fn"><a name="validate" />(<a href="qvalidator.html#State-enum">QValidator.State</a>, int <i>pos</i>) QSpinBox.validate (<i>self</i>, <a href="qstring.html">QString</a> <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>, <a href="qstring.html">QString</a> <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>See also <a href="qspinbox.html#textFromValue">textFromValue</a>() and <a href="qabstractspinbox.html#validate">validate</a>().</p>
<hr /><h2>Qt Signal Documentation</h2><h3 class="fn"><a name="valueChanged" />void valueChanged (int)</h3><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 member function, provided for convenience.</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 width="25%">PyQt 4.0.1 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.trolltech.com">Trolltech AS</a> 2006</td><td align="right" width="25%">Qt 4.1.4</td></tr></table></div></address></body></html>
|