Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QAbstractSpinBox Class Reference

The QAbstractSpinBox class provides a spinwidget and a lineedit to display values. More...

    #include <QAbstractSpinBox>

Inherits QWidget.

Inherited by QDateTimeEdit, QSpinBox, and QDoubleSpinBox.

- List of all members, including inherited members

### Public Types

- enum ButtonSymbols { UpDownArrows, PlusMinus }
- typedef StepEnabled
- enum StepEnabledFlag { StepNone, StepUpEnabled, StepDownEnabled }

### Writable Properties

alignment : Qt::Alignment buttonSymbols : ButtonSymbols frame : bool | slider : bool tracking : bool wrapping : bool

- 33 writable properties inherited from QWidget
- 1 writable property inherited from QObject

### Read-Only Properties

- cleanText : QString
- text : QString

- 24 read-only properties inherited from QWidget

### Public Functions

- QAbstractSpinBox ( QWidget * parent = 0 )
- ~QAbstractSpinBox ()
- void interpretText ()
- void selectAll ()

- 83 public functions inherited from QWidget
- 24 public functions inherited from QObject
- 2 public functions inherited from QPaintDevice

### Public Slots

- 16 public slots inherited from QWidget
- 1 public slot inherited from QObject

### Signals

- 1 signal inherited from QObject

### Static Public Members

- 4 static public members inherited from QWidget
- 4 static public members inherited from QObject

### Protected Functions

- QLineEdit * lineEdit () const
- virtual void stepBy ( int steps )
- virtual StepEnabled stepEnabled () const

- 44 protected functions inherited from QWidget
- 9 protected functions inherited from QObject

## Detailed Description

The QAbstractSpinBox class provides a spinwidget and a lineedit to display values.

The class is designed as a common super class for widgets like QSpinBox, QDoubleSpinBox and QDateTimeEdit

Here are the main properties of the class:

1. text: The text that is displayed in the QAbstractSpinBox.
2. alignment: The alignment of the text in the QAbstractSpinBox.
3. cleanText: The text of the QAbstractSpinBox exluding any prefix/suffix.
4. wrapping: Whether the QAbstractSpinBox wraps from the minimum value to the maximum value and vica versa.
5. tracking: Whether the spinbox validates the text and emits signals for each change in the input.

QAbstractSpinBox provides a virtual stepBy() function that is called whenever the user triggers a step. This function takes an integer value to signify how many steps were taken. E.g. Pressing Qt::Key_Down will trigger a call to stepBy(-1).

QAbstractSpinBox also provide a virtual function stepEnabled() to determine whether stepping up/down is allowed at any point. This function returns a bitset of StepEnabled.

## Member Type Documentation

### enum QAbstractSpinBox::ButtonSymbols

This enum type determines what the buttons in a spin box show.

`QAbstractSpinBox::UpDownArrows` | the buttons show little arrows in the classic style.
`QAbstractSpinBox::PlusMinus` | the buttons show + and - symbols.

See also QAbstractSpinBox::buttonSymbols.

### enum QAbstractSpinBox::StepEnabledFlag
typedef QAbstractSpinBox::StepEnabled

`QAbstractSpinBox::StepNone` |
`QAbstractSpinBox::StepUpEnabled` |
`QAbstractSpinBox::StepDownEnabled` |

The StepEnabled typedef can store a combination of StepEnabledFlag values.

## Property Documentation

### alignment : Qt::Alignment

This property holds the alignment of the spin box.

Possible Values are `Qt::AlignAuto`, `Qt::AlignLeft`, `Qt::AlignRight` and `Qt::AlignHCenter`.

Attempting to set the alignment to an illegal flag combination does nothing.

Access functions:

- Qt::Alignment alignment () const
- void setAlignment ( Qt::Alignment flag )

See also Qt::Alignment.

### buttonSymbols : ButtonSymbols

This property holds the current button symbol mode.

The possible values can be either `UpDownArrows` or `PlusMinus`. The default is `UpDownArrows`.

Access functions:

- ButtonSymbols buttonSymbols () const
- void setButtonSymbols ( ButtonSymbols bs )

See also ButtonSymbols.

### cleanText : QString

This property holds the text of the spin box excluding any , or leading or trailing whitespace.

Access functions:

- QString cleanText () const

See also text, prefix, and suffix.

### frame : bool

This property holds whether the spin box draws itself with a frame.

If enabled (the default) the spin box draws itself inside a two-pixel frame, otherwise the line edit draws itself without any frame.

Access functions:

- bool hasFrame () const
- void setFrame ( bool f )

### slider : bool

This property holds whether the spin box's slider is pressed down.

Access functions:

- bool slider () const
- void setSlider ( bool s )

### text : QString

This property holds the spin box's text, including any and .

There is no default text.

Access functions:

- QString text () const

### tracking : bool

This property holds whether is emitted continuously while typing.

        QSpinBox *sb = new QSpinBox(this);
        sb->setTracking(true);
        // put the keyboard focus in the editor
        // type 1

        // valueChanged(1) is emitted

        // type 2

        // valueChanged(12) is emitted

        // hit return

        // valueChanged(12) is emitted again

By default, tracking is turned off.

Access functions:

- bool tracking () const
- void setTracking ( bool w )

See also QSpinBox::minimum() and QSpinBox::maximum().

### wrapping : bool

This property holds whether the spin box is circular.

If wrapping is true stepping up from maximum() value will take you to the minimum() value and vica versa. Wrapping only make sense if you have minimum() and maximum() values set.

        QSpinBox *sb = new QSpinBox(0, 100, 1, 0, this);
        sb->setValue(100);
        sb->stepUp();
        // value is 100

        sb->setWrapping(true);
        sb->stepUp();
        // value is 0

By default, wrapping is turned off.

Access functions:

- bool wrapping () const
- void setWrapping ( bool w )

See also QSpinBox::minimum() and QSpinBox::maximum().

## Member Function Documentation

### QAbstractSpinBox::QAbstractSpinBox ( QWidget * parent = 0 )

Constructs an abstract spinbox.

The parent arguments is sent to the QWidget constructor.

wrapping defaults to false. tracking defaults to false. alignment defaults to Qt::AlignLeft. // ### qlocale

### QAbstractSpinBox::~QAbstractSpinBox ()

Called when the QAbstractSpinBox is destroyed.

### void QAbstractSpinBox::interpretText ()

This function interprets the text of the spin box. If the value has changed since last interpretation it will emit signals.

### QLineEdit * QAbstractSpinBox::lineEdit () const `[protected]`

This function returns a pointer to the line edit of the spin box.

### void QAbstractSpinBox::selectAll ()

Selects all the text in the spinbox

### void QAbstractSpinBox::stepBy ( int steps ) `[virtual protected]`

Virtual function that is called whenever the user triggers a step. The steps parameter indicates how many steps were taken, e.g. Pressing `Qt::Key_Down` will trigger a call to stepBy(-1), whereas pressing `Qt::Key_Prior` will trigger a call to stepBy(10).

If you subclass QAbstractSpinBox you must reimplement this function. Note that this function is called even if the resulting value will be outside the bounds of minimum and maximum. It's this function's job to handle these situations.

See also QSpinBox::setValue(), QSpinBox::minimum(), and QSpinBox::maximum().

### StepEnabled QAbstractSpinBox::stepEnabled () const `[virtual protected]`

Virtual function that determines whether stepping up and down is legal at any given time.

The up arrow will be painted as disabled unless stepEnabled() & StepUpEnabled != 0.

The default implementation will return (StepUpEnabled| StepDownEnabled) if wrapping is turned on. Else it will return StepDownEnabled if value is > minimum() or'ed with StepUpEnabled if value < maximum().

If you subclass QAbstractSpinBox you will need to reimplement this function.

See also QSpinBox::minimum(), QSpinBox::maximum(), and wrapping().