File: qspinbox.html

package info (click to toggle)
python-qt4 4.12.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 40,300 kB
  • ctags: 6,185
  • sloc: python: 125,988; cpp: 13,291; xml: 292; makefile: 246; php: 27; sh: 2
file content (149 lines) | stat: -rw-r--r-- 16,159 bytes parent folder | download
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?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">&#160;&#160;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <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&#160;<i>parent</i>&#160;=&#160;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&#160;<i>e</i>)</li><li><div class="fn" />QString&#160;<i>str</i> <b><a href="qspinbox.html#fixup">fixup</a></b> (<i>self</i>, QString&#160;<i>str</i>)</li><li><div class="fn" /><b><a href="qspinbox.html#fixup-2">fixup</a></b> (<i>self</i>, QString&#160;<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&#160;<i>max</i>)</li><li><div class="fn" /><b><a href="qspinbox.html#setMinimum">setMinimum</a></b> (<i>self</i>, int&#160;<i>min</i>)</li><li><div class="fn" /><b><a href="qspinbox.html#setPrefix">setPrefix</a></b> (<i>self</i>, QString&#160;<i>p</i>)</li><li><div class="fn" /><b><a href="qspinbox.html#setRange">setRange</a></b> (<i>self</i>, int&#160;<i>min</i>, int&#160;<i>max</i>)</li><li><div class="fn" /><b><a href="qspinbox.html#setSingleStep">setSingleStep</a></b> (<i>self</i>, int&#160;<i>val</i>)</li><li><div class="fn" /><b><a href="qspinbox.html#setSuffix">setSuffix</a></b> (<i>self</i>, QString&#160;<i>s</i>)</li><li><div class="fn" /><b><a href="qspinbox.html#setValue">setValue</a></b> (<i>self</i>, int&#160;<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&#160;<i>v</i>)</li><li><div class="fn" />(QValidator.State, QString&#160;<i>input</i>, int&#160;<i>pos</i>) <b><a href="qspinbox.html#validate">validate</a></b> (<i>self</i>, QString&#160;<i>input</i>, int&#160;<i>pos</i>)</li><li><div class="fn" />(QValidator.State, int&#160;<i>pos</i>) <b><a href="qspinbox.html#validate-2">validate</a></b> (<i>self</i>, QString&#160;<i>input</i>, int&#160;<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&#160;<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&amp;)</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">&amp;</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>&#160;<i>parent</i>&#160;=&#160;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>&#160;<i>e</i>)</h3><p>Reimplemented from <a href="qobject.html#event">QObject.event</a>().</p>


<h3 class="fn"><a name="fixup" />QString&#160;<i>str</i> QSpinBox.fixup (<i>self</i>, QString&#160;<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&#160;<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&#160;<i>max</i>)</h3><h3 class="fn"><a name="setMinimum" />QSpinBox.setMinimum (<i>self</i>, int&#160;<i>min</i>)</h3><h3 class="fn"><a name="setPrefix" />QSpinBox.setPrefix (<i>self</i>, QString&#160;<i>p</i>)</h3><h3 class="fn"><a name="setRange" />QSpinBox.setRange (<i>self</i>, int&#160;<i>min</i>, int&#160;<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&#160;<i>val</i>)</h3><h3 class="fn"><a name="setSuffix" />QSpinBox.setSuffix (<i>self</i>, QString&#160;<i>s</i>)</h3><h3 class="fn"><a name="setValue" />QSpinBox.setValue (<i>self</i>, int&#160;<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&#160;<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&#160;<i>input</i>, int&#160;<i>pos</i>) QSpinBox.validate (<i>self</i>, QString&#160;<i>input</i>, int&#160;<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&#160;<i>pos</i>) QSpinBox.validate (<i>self</i>, QString&#160;<i>input</i>, int&#160;<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&#160;<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&amp;)</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&#160;4.12.1 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qt.io">The Qt Company</a> 2015</td><td align="right" width="25%">Qt&#160;4.8.7</td></tr></table></div></address></body></html>