com.trolltech.qt.gui
Class QIntValidator
java.lang.Object
com.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.gui.QValidator
com.trolltech.qt.gui.QIntValidator
- All Implemented Interfaces:
- QtJambiInterface
public class QIntValidator
- extends QValidator
The QIntValidator class provides a validator that ensures a string contains a valid integer within a specified range. Example of use:
QValidator validator = new QIntValidator(100, 999, this);
QLineEdit edit = new QLineEdit(this);
// the edit lineedit will only accept integers between 100 and 999
edit.setValidator(validator);
Below we present some examples of validators. In practice they would normally be associated with a widget as in the example above.
String str;
int pos = 0;
QIntValidator v= new QIntValidator(100, 999, this);
str = "1";
v.validate(new QValidator.QValidationData(str, pos)); // returns Intermediate
str = "12";
v.validate(new QValidator.QValidationData(str, pos)); // returns Intermediate
str = "123";
v.validate(new QValidator.QValidationData(str, pos)); // returns Acceptable
str = "678";
v.validate(new QValidator.QValidationData(str, pos)); // returns Acceptable
str = "1234";
v.validate(new QValidator.QValidationData(str, pos)); // returns Invalid
str = "-123";
v.validate(new QValidator.QValidationData(str, pos)); // returns Invalid
str = "abc";
v.validate(new QValidator.QValidationData(str, pos)); // returns Invalid
str = "12cm";
v.validate(new QValidator.QValidationData(str, pos)); // returns Invalid
Notice that the value 999 returns Intermediate. Values consisting of a number of digits equal to or less than the max value are considered intermediate. This is intended because the digit that prevents a number to be in range is not necessarily the last digit typed. This also means that an intermediate number can have leading zeros. The minimum and maximum values are set in one call with setRange()
, or individually with setBottom()
and setTop()
.
QIntValidator uses its locale()
to interpret the number. For example, in Arabic locales, QIntValidator will accept Arabic digits. In addition, QIntValidator is always guaranteed to accept a number formatted according to the "C" locale.
See also:
QDoubleValidator
, QRegExpValidator
, and Line Edits Example.
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
QSignalEmitter.AbstractSignal, QSignalEmitter.PrivateSignal0, QSignalEmitter.PrivateSignal1, QSignalEmitter.PrivateSignal2, QSignalEmitter.PrivateSignal3, QSignalEmitter.PrivateSignal4, QSignalEmitter.PrivateSignal5, QSignalEmitter.PrivateSignal6, QSignalEmitter.PrivateSignal7, QSignalEmitter.PrivateSignal8, QSignalEmitter.PrivateSignal9, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal |
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
currentSender |
Constructor Summary |
QIntValidator(int bottom,
int top,
QObject parent)
Constructs a validator with a parent, that accepts integers from minimum to maximum inclusive. |
QIntValidator(QObject parent)
Constructs a validator with a parent object that accepts all integers. |
Method Summary |
int |
bottom()
This property holds the validator's lowest acceptable value. |
void |
setBottom(int arg__1)
This property holds the validator's lowest acceptable value. |
void |
setRange(int bottom,
int top)
Sets the range of the validator to only accept integers between bottom and top inclusive. |
void |
setTop(int arg__1)
This property holds the validator's highest acceptable value. |
int |
top()
This property holds the validator's highest acceptable value. |
Methods inherited from class com.trolltech.qt.core.QObject |
childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty |
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
__qt_signalInitialization |
Methods inherited from class java.lang.Object |
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait |
QIntValidator
public QIntValidator(QObject parent)
- Constructs a validator with a parent object that accepts all integers.
QIntValidator
public QIntValidator(int bottom,
int top,
QObject parent)
- Constructs a validator with a parent, that accepts integers from minimum to maximum inclusive.
bottom
public final int bottom()
- This property holds the validator's lowest acceptable value. By default, this property's value is derived from the lowest signed integer available (typically -2147483647).
- See also:
setRange()
.
setBottom
public final void setBottom(int arg__1)
- This property holds the validator's lowest acceptable value. By default, this property's value is derived from the lowest signed integer available (typically -2147483647).
- See also:
setRange()
.
setTop
public final void setTop(int arg__1)
- This property holds the validator's highest acceptable value. By default, this property's value is derived from the highest signed integer available (typically 2147483647).
- See also:
setRange()
.
top
public final int top()
- This property holds the validator's highest acceptable value. By default, this property's value is derived from the highest signed integer available (typically 2147483647).
- See also:
setRange()
.
setRange
public void setRange(int bottom,
int top)
- Sets the range of the validator to only accept integers between bottom and top inclusive.