TQSpinBox allows the user to choose a value either by clicking the up/down buttons to increase/decrease the value currently displayed or by typing the value directly into the spin box. If the value is entered directly into the spin box, Enter (or Return) must be pressed to apply the new value. The value is usually an integer.
The spin box keeps the value within a numeric range, and to multiples of the lineStep() size (see TQRangeControl for details). 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 lineStep(). The minimum and maximum value and the step size can be set using one of the constructors, and can be changed later with setMinValue(), setMaxValue() and setLineStep().
Most spin boxes are directional, but TQSpinBox 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. Use setWrapping() if you want circular behavior.
The displayed value can be prepended and appended with arbitrary strings indicating, for example, currency or the unit of measurement. See setPrefix() and setSuffix(). The text in the spin box is retrieved with text() (which includes any prefix() and suffix()), or with cleanText() (which has no prefix(), no suffix() and no leading or trailing whitespace). currentValueText() returns the spin box's current value as text.
.PP
Normally the spin box displays up and down arrows in the buttons. You can use setButtonSymbols() to change the display to show \fB+\fR and \fB-\fR symbols if you prefer. In either case the up and down arrow keys work as expected.
It is often desirable to give the user a special (often default) choice in addition to the range of numeric values. See setSpecialValueText() for how to do this with TQSpinBox.
TQSpinBox can easily be subclassed to allow the user to input things other than an integer value as long as the allowed input can be mapped to a range of integers. This can be done by overriding the virtual functions mapValueToText() and mapTextToValue(), and setting another suitable validator using setValidator().
For example, these functions could be changed so that the user provided values from 0.0 to 10.0, or -1 to signify 'Auto', while the range of integers used inside the program would be -1 to 100:
Constructs a spin box that allows values from \fIminValue\fR to \fImaxValue\fR inclusive, with step amount \fIstep\fR. The value is initially set to \fIminValue\fR.
.PP
The spin box is called \fIname\fR and has parent \fIparent\fR.
.PP
See also minValue, maxValue, setRange(), lineStep, and setSteps().
Returns the full text calculated from the current value, including any prefix and suffix. If there is special value text and the value is minValue() the specialValueText() is returned.
.SH "bool TQSpinBox::eventFilter ( TQObject * o, TQEvent * ev )\fC [virtual protected]\fR"
Intercepts and handles the events coming to the embedded TQLineEdit that have special meaning for the TQSpinBox. The object is passed as \fIo\fR and the event is passed as \fIev\fR.
TQSpinBox calls this after the user has manually edited the contents of the spin box (i.e. by typing in the embedded TQLineEdit, rather than using the up/down buttons/keys).
The default implementation of this function interprets the new text using mapTextToValue(). If mapTextToValue() is successful, it changes the spin box's value; if not, the value is left unchanged.
This virtual function is used by the spin box whenever it needs to interpret text entered by the user as a value. The text is available as text() and as cleanText(), and this function must parse it if possible. If \fIok\fR is not 0: if it parses the text successfully, \fI*ok\fR is set to TRUE; otherwise \fI*ok\fR is set to FALSE.
.PP
Subclasses that need to display spin box values in a non-numeric way need to reimplement this function.
This virtual function is used by the spin box whenever it needs to display value \fIv\fR. The default implementation returns a string containing \fIv\fR printed in the standard way. Reimplementations may return anything. (See the example in the detailed description.)
This virtual function is called by TQRangeControl whenever the range has changed. It adjusts the default validator and updates the display; if you need additional processing, you can reimplement this function.
Sets the validator to \fIv\fR. The validator controls what keyboard input is accepted when the user is editing in the value field. The default is to use a suitable TQIntValidator.
Sets whether it is possible to step the value from the highest value to the lowest value and vice versa to \fIon\fR. See the "wrapping" property for details.
Decreases the spin box's value one lineStep(), wrapping as necessary if wrapping() is TRUE. This is the same as clicking on the pointing-down button and can be used for keyboard accelerators, for example.
.PP
See also stepUp(), subtractLine(), lineStep, setSteps(), value, and value.
Increases the spin box's value by one lineStep(), wrapping as necessary if wrapping() is TRUE. This is the same as clicking on the pointing-up button and can be used for keyboard accelerators, for example.
.PP
See also stepDown(), addLine(), lineStep, setSteps(), value, and value.
Updates the contents of the embedded TQLineEdit to reflect the current value using mapValueToText(). Also enables/disables the up/down push buttons accordingly.
This virtual function is called by TQRangeControl whenever the value has changed. The TQSpinBox reimplementation updates the display and emits the valueChanged() signals; if you need additional processing, either reimplement this or connect to one of the valueChanged() signals.
This signal is emitted every time the value of the spin box changes; the new value is passed in \fIvalue\fR. This signal will be emitted as a result of a call to setValue(), or because the user changed the value by using a keyboard accelerator or mouse click, etc.
.PP
Note that the valueChanged() signal is emitted \fIevery\fR time, not just for the "last" step; i.e. if the user clicks "up" three times, this signal is emitted three times.
.PP
See also value.
.PP
Examples:
.)l listbox/listbox.cpp, qfd/fontdisplayer.cpp, and scribble/scribble.cpp.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
This signal is emitted whenever the valueChanged( int ) signal is emitted, i.e. every time the value of the spin box changes (whatever the cause, e.g. by setValue(), by a keyboard accelerator, by mouse clicks, etc.).
.PP
The \fIvalueText\fR parameter is the same string that is displayed in the edit field of the spin box.
.PP
See also value, prefix, suffix, and specialValueText.
Returns TRUE if it is possible to step the value from the highest value to the lowest value and vice versa; otherwise returns FALSE. See the "wrapping" property for details.
.SS "Property Documentation"
.SH "ButtonSymbols buttonSymbols"
This property holds the current button symbol mode.
.PP
The possible values can be either UpDownArrows or PlusMinus. The default is UpDownArrows.
.PP
See also ButtonSymbols.
.PP
Set this property's value with setButtonSymbols() and get this property's value with buttonSymbols().
The prefix is prepended to the start of the displayed value. Typical use is to display a unit of measurement or a currency symbol. For example:
.PP
.nf
.br
sb->setPrefix( "$" );
.br
.fi
.PP
To turn off the prefix display, set this property to an empty string. The default is no prefix. The prefix is not displayed for the minValue() if specialValueText() is not empty.
If set, the spin box will display this text instead of a numeric value whenever the current value is equal to minVal(). Typical use is to indicate that this choice has a special (default) meaning.
.PP
For example, if your spin box allows the user to choose the margin width in a print dialog and your application is able to automatically choose a good margin width, you can set up the spin box like this:
The user will then be able to choose a margin width from 0-20 millimeters or select "Auto" to leave it to the application to choose. Your code must then interpret the spin box value of -1 as the user requesting automatic margin width.
.PP
All values are displayed with the prefix() and suffix() (if set), \fIexcept\fR for the special value, which only shows the special value text.
.PP
To turn off the special-value text display, call this function with an empty string. The default is no special-value text, i.e. the numeric value is shown as usual.
The suffix is appended to the end of the displayed value. Typical use is to display a unit of measurement or a currency symbol. For example:
.PP
.nf
.br
sb->setSuffix( " km" );
.br
.fi
.PP
To turn off the suffix display, set this property to an empty string. The default is no suffix. The suffix is not displayed for the minValue() if specialValueText() is not empty.
This property holds whether it is possible to step the value from the highest value to the lowest value and vice versa.
.PP
By default, wrapping is turned off.
.PP
If you have a range of 0..100 and wrapping is off when the user reaches 100 and presses the Up Arrow nothing will happen; but if wrapping is on the value will change from 100 to 0, then to 1, etc. When wrapping is on, navigating past the highest value takes you to the lowest and vice versa.
.PP
See also minValue, maxValue, and setRange().
.PP
Set this property's value with setWrapping() and get this property's value with wrapping().