|  | Home · All Classes · Modules

# QAbstractSpinBox Class Reference
[QtGui module]

The QAbstractSpinBox class provides a spinbox and a line edit to display values. More...

Inherits QWidget.

Inherited by QDateTimeEdit, QDoubleSpinBox and QSpinBox.

### Types

- enum ButtonSymbols { UpDownArrows, PlusMinus, NoButtons }
- enum CorrectionMode { CorrectToPreviousValue, CorrectToNearestValue }
- class StepEnabled
- enum StepEnabledFlag { StepNone, StepUpEnabled, StepDownEnabled }

### Methods

- __init__ (self, QWidget parent = None)
- Qt.Alignment alignment (self)
- ButtonSymbols buttonSymbols (self)
- changeEvent (self, QEvent)
- clear (self)
- closeEvent (self, QCloseEvent)
- contextMenuEvent (self, QContextMenuEvent)
- CorrectionMode correctionMode (self)
- bool event (self, QEvent)
- QString input fixup (self, QString input)
- fixup (self, QString)
- focusInEvent (self, QFocusEvent)
- focusOutEvent (self, QFocusEvent)
- bool hasAcceptableInput (self)
- bool hasFrame (self)
- hideEvent (self, QHideEvent)
- initStyleOption (self, QStyleOptionSpinBox)
- QVariant inputMethodQuery (self, Qt.InputMethodQuery)
- interpretText (self)
- bool isAccelerated (self)
- bool isReadOnly (self)
- bool keyboardTracking (self)
- keyPressEvent (self, QKeyEvent)
- keyReleaseEvent (self, QKeyEvent)
- QLineEdit lineEdit (self)
- QSize minimumSizeHint (self)
- mouseMoveEvent (self, QMouseEvent)
- mousePressEvent (self, QMouseEvent)
- mouseReleaseEvent (self, QMouseEvent)
- paintEvent (self, QPaintEvent)
- resizeEvent (self, QResizeEvent)
- selectAll (self)
- setAccelerated (self, bool)
- setAlignment (self, Qt.Alignment)
- setButtonSymbols (self, ButtonSymbols)
- setCorrectionMode (self, CorrectionMode)
- setFrame (self, bool)
- setKeyboardTracking (self, bool)
- setLineEdit (self, QLineEdit)
- setReadOnly (self, bool)
- setSpecialValueText (self, QString)
- setWrapping (self, bool)
- showEvent (self, QShowEvent)
- QSize sizeHint (self)
- QString specialValueText (self)
- stepBy (self, int)
- stepDown (self)
- StepEnabled stepEnabled (self)
- stepUp (self)
- QString text (self)
- timerEvent (self, QTimerEvent)
- (QValidator.State, QString input, int pos) validate (self, QString input, int pos)
- (QValidator.State, int) validate (self, QString, int)
- wheelEvent (self, QWheelEvent)
- bool wrapping (self)

### Qt Signals

- void editingFinished ()

## Detailed Description

The QAbstractSpinBox class provides a spinbox and a line edit 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. wrapping: Whether the QAbstractSpinBox wraps from the minimum value to the maximum value and vica versa.

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.

See also QAbstractSlider, QSpinBox, QDoubleSpinBox, QDateTimeEdit, and Spin Boxes Example.

## Type Documentation

### QAbstractSpinBox.ButtonSymbols

This enum type describes the symbols that can be displayed on the buttons in a spin box.

Constant | Value | Description
--- | --- | ---
`QAbstractSpinBox.UpDownArrows` | `0` | Little arrows in the classic style.
`QAbstractSpinBox.PlusMinus` | `1` | + and - symbols.
`QAbstractSpinBox.NoButtons` | `2` | Don't display buttons.

See also QAbstractSpinBox.buttonSymbols.

### QAbstractSpinBox.CorrectionMode

This enum type describes the mode the spinbox will use to correct an Intermediate value if editing finishes.

Constant | Value | Description
--- | --- | ---
`QAbstractSpinBox.CorrectToPreviousValue` | `0` | The spinbox will revert to the last valid value.
`QAbstractSpinBox.CorrectToNearestValue` | `1` | The spinbox will revert to the nearest valid value.

See also correctionMode.

### QAbstractSpinBox.StepEnabledFlag

Constant | Value
--- | ---
`QAbstractSpinBox.StepNone` | `0x00`
`QAbstractSpinBox.StepUpEnabled` | `0x01`
`QAbstractSpinBox.StepDownEnabled` | `0x02`

The StepEnabled type is a typedef for QFlags<StepEnabledFlag>. It stores an OR combination of StepEnabledFlag values.

## Method Documentation

### QAbstractSpinBox.__init__ (self, QWidget parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs an abstract spinbox with the given parent with default wrapping, and alignment properties.

### Qt.Alignment QAbstractSpinBox.alignment (self)

### ButtonSymbols QAbstractSpinBox.buttonSymbols (self)

### QAbstractSpinBox.changeEvent (self, QEvent)

Reimplemented from QWidget.changeEvent().

### QAbstractSpinBox.clear (self)

This method is also a Qt slot with the C++ signature `void clear()`.

Clears the lineedit of all text but prefix and suffix.

### QAbstractSpinBox.closeEvent (self, QCloseEvent)

Reimplemented from QWidget.closeEvent().

### QAbstractSpinBox.contextMenuEvent (self, QContextMenuEvent)

Reimplemented from QWidget.contextMenuEvent().

### CorrectionMode QAbstractSpinBox.correctionMode (self)

### bool QAbstractSpinBox.event (self, QEvent)

Reimplemented from QObject.event().

### QString input QAbstractSpinBox.fixup (self, QString input)

This virtual function is called by the QAbstractSpinBox if the input is not validated to QValidator.Acceptable when Return is pressed or interpretText() is called. It will try to change the text so it is valid. Reimplemented in the various subclasses.

### QAbstractSpinBox.fixup (self, QString)

### QAbstractSpinBox.focusInEvent (self, QFocusEvent)

Reimplemented from QWidget.focusInEvent().

### QAbstractSpinBox.focusOutEvent (self, QFocusEvent)

Reimplemented from QWidget.focusOutEvent().

### bool QAbstractSpinBox.hasAcceptableInput (self)

### bool QAbstractSpinBox.hasFrame (self)

### QAbstractSpinBox.hideEvent (self, QHideEvent)

Reimplemented from QWidget.hideEvent().

### QAbstractSpinBox.initStyleOption (self, QStyleOptionSpinBox)

Initialize option with the values from this QSpinBox. This method is useful for subclasses when they need a QStyleOptionSpinBox, but don't want to fill in all the information themselves.

See also QStyleOption.initFrom().

### QVariant QAbstractSpinBox.inputMethodQuery (self, Qt.InputMethodQuery)

Reimplemented from QWidget.inputMethodQuery().

### QAbstractSpinBox.interpretText (self)

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

### bool QAbstractSpinBox.isAccelerated (self)

### bool QAbstractSpinBox.isReadOnly (self)

### bool QAbstractSpinBox.keyboardTracking (self)

### QAbstractSpinBox.keyPressEvent (self, QKeyEvent)

Reimplemented from QWidget.keyPressEvent().

This function handles keyboard input.

The following keys are handled specifically:

Enter/Return | This will reinterpret the text and emit a signal even if the value has not changed since last time a signal was emitted.
Up | This will invoke stepBy(1)
Down | This will invoke stepBy(-1)
Page up | This will invoke stepBy(10)
Page down | This will invoke stepBy(-10)

### QAbstractSpinBox.keyReleaseEvent (self, QKeyEvent)

Reimplemented from QWidget.keyReleaseEvent().

### QLineEdit QAbstractSpinBox.lineEdit (self)

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

See also setLineEdit().

### QSize QAbstractSpinBox.minimumSizeHint (self)

Reimplemented from QWidget.minimumSizeHint().

### QAbstractSpinBox.mouseMoveEvent (self, QMouseEvent)

Reimplemented from QWidget.mouseMoveEvent().

### QAbstractSpinBox.mousePressEvent (self, QMouseEvent)

Reimplemented from QWidget.mousePressEvent().

### QAbstractSpinBox.mouseReleaseEvent (self, QMouseEvent)

Reimplemented from QWidget.mouseReleaseEvent().

### QAbstractSpinBox.paintEvent (self, QPaintEvent)

Reimplemented from QWidget.paintEvent().

### QAbstractSpinBox.resizeEvent (self, QResizeEvent)

Reimplemented from QWidget.resizeEvent().

### QAbstractSpinBox.selectAll (self)

This method is also a Qt slot with the C++ signature `void selectAll()`.

Selects all the text in the spinbox except the prefix and suffix.

### QAbstractSpinBox.setAccelerated (self, bool)

### QAbstractSpinBox.setAlignment (self, Qt.Alignment)

### QAbstractSpinBox.setButtonSymbols (self, ButtonSymbols)

### QAbstractSpinBox.setCorrectionMode (self, CorrectionMode)

### QAbstractSpinBox.setFrame (self, bool)

### QAbstractSpinBox.setKeyboardTracking (self, bool)

### QAbstractSpinBox.setLineEdit (self, QLineEdit)

The QLineEdit argument has it's ownership transferred to Qt.

Sets the line edit of the spinbox to be lineEdit instead of the current line edit widget. lineEdit can not be 0.

QAbstractSpinBox takes ownership of the new lineEdit

If QLineEdit.validator() for the lineEdit returns 0, the internal validator of the spinbox will be set on the line edit.

See also lineEdit().

### QAbstractSpinBox.setReadOnly (self, bool)

### QAbstractSpinBox.setSpecialValueText (self, QString)

### QAbstractSpinBox.setWrapping (self, bool)

### QAbstractSpinBox.showEvent (self, QShowEvent)

Reimplemented from QWidget.showEvent().

### QSize QAbstractSpinBox.sizeHint (self)

Reimplemented from QWidget.sizeHint().

### QString QAbstractSpinBox.specialValueText (self)

### QAbstractSpinBox.stepBy (self, int)

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.

### QAbstractSpinBox.stepDown (self)

This method is also a Qt slot with the C++ signature `void stepDown()`.

Steps down by one linestep Calling this slot is analogous to calling stepBy(-1);

See also stepBy() and stepUp().

### StepEnabled QAbstractSpinBox.stepEnabled (self)

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().

### QAbstractSpinBox.stepUp (self)

This method is also a Qt slot with the C++ signature `void stepUp()`.

Steps up by one linestep Calling this slot is analogous to calling stepBy(1);

See also stepBy() and stepDown().

### QString QAbstractSpinBox.text (self)

### QAbstractSpinBox.timerEvent (self, QTimerEvent)

Reimplemented from QObject.timerEvent().

### (QValidator.State, QString input, int pos) QAbstractSpinBox.validate (self, QString input, int pos)

This virtual function is called by the QAbstractSpinBox to determine whether input is valid. The pos parameter indicates the position in the string. Reimplemented in the various subclasses.

### (QValidator.State, int) QAbstractSpinBox.validate (self, QString, int)

### QAbstractSpinBox.wheelEvent (self, QWheelEvent)

Reimplemented from QWidget.wheelEvent().

### bool QAbstractSpinBox.wrapping (self)

## Qt Signal Documentation

### void editingFinished ()

This is the default overload of this signal.

This signal is emitted editing is finished. This happens when the spinbox loses focus and when enter is pressed.