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
|
<?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>QValidator 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">QValidator Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QValidator class provides validation of input text. <a href="#details">More...</a></p>
<p>Inherits <a href="qobject.html">QObject</a>.</p><p>Inherited by <a href="qdoublevalidator.html">QDoubleValidator</a>, <a href="qintvalidator.html">QIntValidator</a> and <a href="qregexpvalidator.html">QRegExpValidator</a>.</p><h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qvalidator.html#State-enum">State</a></b> { Invalid, Intermediate, Acceptable }</li></ul><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qvalidator.html#QValidator">__init__</a></b> (<i>self</i>, QObject <i>parent</i>)</li><li><div class="fn" /><b><a href="qvalidator.html#fixup">fixup</a></b> (<i>self</i>, QString)</li><li><div class="fn" />(State, int) <b><a href="qvalidator.html#validate">validate</a></b> (<i>self</i>, QString, int)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QValidator class provides validation of input text.</p>
<p>The class itself is abstract. Two subclasses, <a href="qintvalidator.html">QIntValidator</a> and <a href="qdoublevalidator.html">QDoubleValidator</a>, provide basic numeric-range checking, and <a href="qregexpvalidator.html">QRegExpValidator</a> provides general checking using a custom regular expression.</p>
<p>If the built-in validators aren't sufficient, you can subclass QValidator. The class has two virtual functions: <a href="qvalidator.html#validate">validate</a>() and <a href="qvalidator.html#fixup">fixup</a>().</p>
<p><a href="qvalidator.html#validate">validate</a>() must be implemented by every subclass. It returns <a href="qvalidator.html#State-enum">Invalid</a>, <a href="qvalidator.html#State-enum">Intermediate</a> or <a href="qvalidator.html#State-enum">Acceptable</a> depending on whether its argument is valid (for the subclass's definition of valid).</p>
<p>These three states require some explanation. An <a href="qvalidator.html#State-enum">Invalid</a> string is <i>clearly</i> invalid. <a href="qvalidator.html#State-enum">Intermediate</a> is less obvious: the concept of validity is difficult to apply when the string is incomplete (still being edited). QValidator defines <a href="qvalidator.html#State-enum">Intermediate</a> as the property of a string that is neither clearly invalid nor acceptable as a final result. <a href="qvalidator.html#State-enum">Acceptable</a> means that the string is acceptable as a final result. One might say that any string that is a plausible intermediate state during entry of an <a href="qvalidator.html#State-enum">Acceptable</a> string is <a href="qvalidator.html#State-enum">Intermediate</a>.</p>
<p>Here are some examples:</p>
<ul>
<li>For a line edit that accepts integers from 10 to 999 inclusive, 42 and 123 are <a href="qvalidator.html#State-enum">Acceptable</a>, the empty string and 5 are <a href="qvalidator.html#State-enum">Intermediate</a>, and "asdf" and 1114 is <a href="qvalidator.html#State-enum">Invalid</a>.</li>
<li>For an editable combobox that accepts URLs, any well-formed URL is <a href="qvalidator.html#State-enum">Acceptable</a>, "http://www.trolltech.com/," is <a href="qvalidator.html#State-enum">Intermediate</a> (it might be a cut and paste action that accidentally took in a comma at the end), the empty string is <a href="qvalidator.html#State-enum">Intermediate</a> (the user might select and delete all of the text in preparation for entering a new URL) and "http:///./" is <a href="qvalidator.html#State-enum">Invalid</a>.</li>
<li>For a spin box that accepts lengths, "11cm" and "1in" are <a href="qvalidator.html#State-enum">Acceptable</a>, "11" and the empty string are <a href="qvalidator.html#State-enum">Intermediate</a>, and "http://www.trolltech.com" and "hour" are <a href="qvalidator.html#State-enum">Invalid</a>.</li>
</ul>
<p><a href="qvalidator.html#fixup">fixup</a>() is provided for validators that can repair some user errors. The default implementation does nothing. <a href="qlineedit.html">QLineEdit</a>, for example, will call <a href="qvalidator.html#fixup">fixup</a>() if the user presses Enter (or Return) and the content is not currently valid. This allows the <a href="qvalidator.html#fixup">fixup</a>() function the opportunity of performing some magic to make an <a href="qvalidator.html#State-enum">Invalid</a> string <a href="qvalidator.html#State-enum">Acceptable</a>.</p>
<p>QValidator is typically used with <a href="qlineedit.html">QLineEdit</a>, <a href="qspinbox.html">QSpinBox</a> and <a href="qcombobox.html">QComboBox</a>.</p>
<hr /><h2>Type Documentation</h2><h3 class="fn"><a name="State-enum" />QValidator.State</h3><p>This enum type defines the states in which a validated string can exist.</p>
<table border="1" cellpadding="2" cellspacing="1" width="100%">
<tr>
<th width="25%">Constant</th>
<th width="15%">Value</th>
<th width="60%">Description</th>
</tr>
<tr>
<td valign="top"><tt>QValidator.Invalid</tt></td>
<td align="center" valign="top"><tt>0</tt></td>
<td valign="top">The string is <i>clearly</i> invalid.</td>
</tr>
<tr>
<td valign="top"><tt>QValidator.Intermediate</tt></td>
<td align="center" valign="top"><tt>1</tt></td>
<td valign="top">The string is a plausible intermediate value during editing.</td>
</tr>
<tr>
<td valign="top"><tt>QValidator.Acceptable</tt></td>
<td align="center" valign="top"> </td>
<td valign="top">The string is acceptable as a final result; i.e. it is valid.</td>
</tr>
</table>
<br />
<br />
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QValidator" />QValidator.__init__ (<i>self</i>, <a href="qobject.html">QObject</a> <i>parent</i>)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Sets up the validator. The <i>parent</i> parameter is passed on to the <a href="qobject.html">QObject</a> constructor.</p>
<h3 class="fn"><a name="fixup" />QValidator.fixup (<i>self</i>, <a href="qstring.html">QString</a>)</h3><p>This function attempts to change <i>input</i> to be valid according to this validator's rules. It need not result in a valid string: callers of this function must re-test afterwards; the default does nothing.</p>
<p>Reimplementations of this function can change <i>input</i> even if they do not produce a valid string. For example, an ISBN validator might want to delete every character except digits and "-", even if the result is still not a valid ISBN; a surname validator might want to remove whitespace from the start and end of the string, even if the resulting string is not in the list of accepted surnames.</p>
<h3 class="fn"><a name="validate" />(<a href="qvalidator.html#State-enum">State</a>, int) QValidator.validate (<i>self</i>, <a href="qstring.html">QString</a>, int)</h3><p>This method is abstract and should be reimplemented in any sub-class.</p><p>This virtual function returns <a href="qvalidator.html#State-enum">Invalid</a> if <i>input</i> is invalid according to this validator's rules, <a href="qvalidator.html#State-enum">Intermediate</a> if it is likely that a little more editing will make the input acceptable (e.g. the user types "4" into a widget which accepts integers between 10 and 99), and <a href="qvalidator.html#State-enum">Acceptable</a> if the input is valid.</p>
<p>The function can change both <i>input</i> and <i>pos</i> (the cursor position) if required.</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>
|