Qtopia Home - Classes - Hierachy - Annotated - Functions - Licenses - Reference |
|
The QSpinBox class provides a spin box widget, sometimes called up-down widget, little arrows widget or spin button. More...
#include <qspinbox.h>
Inherits QFrame and QRangeControl.
Inherited by QPETimeEdit.
The QSpinBox class provides a spin box widget, sometimes called up-down widget, little arrows widget or spin button.
QSpinBox 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. Usually the value is an integer.
Every time the value changes, QSpinBox emits the valueChanged() signal. The current value can be fetched with value() and set with setValue().
The spin box clamps the value within a numeric range, see QRangeControl for details. Clicking the up/down down buttons (or using the keyboard accelerators: Up-arrow and Down-arrow) will increase or decrease the current value in steps of size lineStep().
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. Use setWrapping() if you want circular behavior.
The displayed value can be prepended and/or appended with an arbitrary string indicating for example the unit of measurement. See setPrefix() and setSuffix().
Normally, the spin box displays up and down arrows in the buttons. You can use setButtonSymbols() to change the display to show + and - symbols, if this is clearer for your intended purpose. In either case, the up and down arrow keys always work.
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 QSpinBox.
The default QWidget::focusPolicy() is StrongFocus.
QSpinBox can easily be subclassed to allow the user to input other things than an integer value, as long as the allowed input can be mapped down 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 function could be changed so that the user provided values from 0.0 to 10.0 while the range of integers used inside the program would be 0 to 100:
class MySpinBox : public QSpinBox {
public:
...
QString mapValueToText( int value )
{
return QString("%1.%2").arg(value/10).arg(value%10);
}
int mapTextToValue( bool* ok )
{
return int(text().toFloat()*10);
}
};
See also QScrollBar, QSlider, and GUI Design Handbook: Spin Box.
See also minValue(), maxValue(), setRange(), lineStep(), and setSteps().
See also minValue(), maxValue(), setRange(), lineStep(), and setSteps().
See also setButtonSymbols() and ButtonSymbols.
See also text(), setPrefix(), and setSuffix().
Reimplemented from QObject.
The default implementation of this function interprets the new text using mapTextToValue(). If mapTextToValue() is successful, it changes the spin box' value. If not the value if left unchanged.
Reimplement this function in in a subclass if you want a specialized spin box, handling something else than integers. It should call text() (or cleanText() ) and return the value corresponding to that text. If the text does not represent a legal value (uninterpretable), the bool pointed to by ok should be set to FALSE.
This function need not be concerned with special-value text, the QSpinBox handles that automatically.
See also interpretText() and mapValueToText().
Reimplement this function in in a subclass if you want a specialized spin box, handling something else than integers. This function need not be concerned with prefix or suffix or special-value text, the QSpinBox handles that automatically.
See also updateDisplay() and mapTextToValue().
See also setPrefix(), setSuffix(), and suffix().
Reimplemented from QRangeControl.
See also buttonSymbols() and ButtonSymbols.
Calls the virtual stepChange() function if the new line step is different from the previous setting.
See also lineStep(), QRangeControl::setSteps(), and setRange().
See also setRange().
See also setRange().
sb->setPrefix("$");
To turn off the prefix display, call this function with an empty string as parameter. The default is no prefix.
See also prefix(), setSuffix(), and suffix().
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:
QSpinBox marginBox( -1, 20, 1, parent, "marginBox" );
marginBox->setSuffix( " mm" );
marginBox->setSpecialValueText( "Auto" );
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.
Neither prefix nor suffix, if set, are added to the special-value text when displayed.
To turn off the special-value text display, call this function with an empty string as parameter. The default is no special-value text, i.e. the numeric value is shown as usual.
See also specialValueText().
sb->setSuffix("cm");
To turn off the suffix display, call this function with an empty string as parameter. The default is no suffix.
See also suffix(), setPrefix(), and prefix().
Use setValidator(0) to turn off input validation (entered input will still be clamped to the range of the spinbox).
See also wrapping(), minValue(), maxValue(), and setRange().
See also setSpecialValueText().
See also stepUp(), subtractLine(), lineStep(), setSteps(), setValue(), and value().
Reimplemented in QPETimeEdit.
See also stepDown(), addLine(), lineStep(), setSteps(), setValue(), and value().
Reimplemented in QPETimeEdit.
See also setSuffix() and setPrefix().
See also value().
See also mapValueToText().
See also setValidator() and QValidator.
Reimplemented from QRangeControl.
This signal is emitted every time the value of the spin box changes (whatever the cause - by setValue(), by a keyboard accelerator, by mouse clicks etc.).
Note that it is emitted every time, not just for the "final" step - if the user clicks 'up' three times, this signal is emitted three times.
See also value().
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 - by setValue(), by a keyboard accelerator, by mouse clicks etc.).
The valueText parameter is the same string that is displayed in the edit field of the spin box.
See also value().
This file is part of the Qtopia platform, copyright © 1995-2005 Trolltech, all rights reserved.
| Copyright © 2005 Trolltech | Trademarks | Qtopia version 2.2.0
|