6.0.0-rc4Source

QAbstractSpinBox Class

The QAbstractSpinBox class is the base of the widgets that show a value in a text with two buttons that step it. More…

Header#include <QAbstractSpinBox>
CMaketarget_link_libraries(app PRIVATE Nt::Widgets)
ModuleNt Widgets C++ Classes
InheritsQWidget
Inherited byQDateTimeEdit, QDoubleSpinBox, QSpinBox

List of all members, including inherited members

Public Types

Public Functions

QAbstractSpinBox(QWidget *parent = nullptr)
~QAbstractSpinBox()
QStringtext() const
QStringspecialValueText() const
voidsetSpecialValueText(const QString &text)
boolwrapping() const
voidsetWrapping(bool wrapping)
boolisReadOnly() const
voidsetReadOnly(bool readOnly)
boolkeyboardTracking() const
voidsetKeyboardTracking(bool enable)
voidinterpretText()
virtual voidstepBy(int steps)

Reimplemented Public Functions

Public Slots

voidstepUp()
voidstepDown()
voidselectAll()
virtual voidclear()

Signals

Protected Functions

virtual StepEnabledstepEnabled() const
QLineEdit *lineEdit() const

Reimplemented Protected Functions

Detailed Description

A spin box has a line edit and a button to step up and one to step down. The arrow keys, Page Up and Page Down, and the mouse wheel step too. QSpinBox holds an integer and QDoubleSpinBox a floating-point number; a subclass of QAbstractSpinBox that holds another kind of value reimplements stepBy() and stepEnabled().

When the value is the smallest, the spin box can show a word instead of the number:

QSpinBox *delay = new QSpinBox(window);
delay->setRange(0, 60);
delay->setSuffix(" s");
delay->setSpecialValueText("Off");

See also QSpinBox and QDoubleSpinBox.

Differences from Qt

There is no alignment, buttonSymbols, accelerated, correctionMode, frame or showGroupSeparator, and no validate() or fixup(): the subclasses check what the user types. The buttons do not repeat while they are held. A subclass outside Nt can reimplement stepBy() and stepEnabled(), but the text is always that of a QSpinBox or a QDoubleSpinBox.

Member Type Documentation

typedef QAbstractSpinBox::StepEnabled

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

enum QAbstractSpinBox::StepEnabledFlag

Which ways the spin box can step, as returned by stepEnabled().

ConstantDescription
QAbstractSpinBox::StepNoneNeither.
QAbstractSpinBox::StepUpEnabledUp.
QAbstractSpinBox::StepDownEnabledDown.

Member Function Documentation

[explicit] QAbstractSpinBox::QAbstractSpinBox(QWidget *parent = nullptr)

Constructs a spin box with the given parent.

[override] QAbstractSpinBox::~QAbstractSpinBox()

Destroys the spin box.

[override, protected] void QAbstractSpinBox::changeEvent(QEvent *event)

Reimplements QWidget::changeEvent().

[slot, virtual] void QAbstractSpinBox::clear()

Clears the text but for the prefix and the suffix. The value does not change until the user types a new one.

[signal] void QAbstractSpinBox::editingFinished()

This signal is emitted when the user has finished editing the text: Return or Enter is pressed, or the spin box loses the focus.

void QAbstractSpinBox::interpretText()

Takes the text that the user typed as the value, as when editing finishes, without emitting editingFinished().

bool QAbstractSpinBox::isReadOnly() const

Returns whether the user cannot change the value. The default is false.

See also setReadOnly().

bool QAbstractSpinBox::keyboardTracking() const

Returns whether the value follows the text as the user types. The default is true.

See also setKeyboardTracking().

[override, protected] void QAbstractSpinBox::keyPressEvent(QKeyEvent *event)

Reimplements QWidget::keyPressEvent().

Up and Down step by one single step, Page Up and Page Down by ten.

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

Returns the line edit that shows the text.

[override] QSize QAbstractSpinBox::minimumSizeHint() const

Reimplements QWidget::minimumSizeHint().

[override, protected] void QAbstractSpinBox::mousePressEvent(QMouseEvent *event)

Reimplements QWidget::mousePressEvent().

[override, protected] void QAbstractSpinBox::mouseReleaseEvent(QMouseEvent *event)

Reimplements QWidget::mouseReleaseEvent().

[override, protected] void QAbstractSpinBox::paintEvent(QPaintEvent *event)

Reimplements QWidget::paintEvent().

[override, protected] void QAbstractSpinBox::resizeEvent(QResizeEvent *event)

Reimplements QWidget::resizeEvent().

[slot] void QAbstractSpinBox::selectAll()

Selects the text between the prefix and the suffix.

void QAbstractSpinBox::setKeyboardTracking(bool enable)

Sets whether the value follows the text as the user types to enable. Without it, the value changes when the user presses Return or the spin box loses the focus.

See also keyboardTracking().

void QAbstractSpinBox::setReadOnly(bool readOnly)

Sets whether the user cannot change the value to readOnly. A read-only spin box shows its value and lets the text be selected, but it does not step and its text cannot be edited.

See also isReadOnly().

void QAbstractSpinBox::setSpecialValueText(const QString &text)

Sets the text shown instead of the smallest value to text. Typing the text sets the smallest value. An empty text shows the number.

See also specialValueText().

void QAbstractSpinBox::setWrapping(bool wrapping)

Sets whether stepping past one end goes round to the other to wrapping.

See also wrapping().

[override] QSize QAbstractSpinBox::sizeHint() const

Reimplements QWidget::sizeHint().

QString QAbstractSpinBox::specialValueText() const

Returns the text that is shown instead of the smallest value, or an empty string if the number is shown.

See also setSpecialValueText().

[virtual] void QAbstractSpinBox::stepBy(int steps)

Steps the value by steps single steps, up if steps is positive. The default implementation does nothing; QSpinBox and QDoubleSpinBox reimplement it.

See also stepUp(), stepDown() and stepEnabled().

[slot] void QAbstractSpinBox::stepDown()

Steps the value down by one single step.

See also stepBy().

[virtual, protected] StepEnabled QAbstractSpinBox::stepEnabled() const

Returns which ways the spin box can step. The default implementation returns StepNone for a read-only spin box and both ways otherwise; QSpinBox and QDoubleSpinBox look at the value and the range.

See also stepBy().

[slot] void QAbstractSpinBox::stepUp()

Steps the value up by one single step.

See also stepBy().

QString QAbstractSpinBox::text() const

Returns the text of the spin box: the value with the prefix and the suffix, or what the user is typing.

See also QSpinBox::cleanText().

[override, protected] void QAbstractSpinBox::wheelEvent(QWheelEvent *event)

Reimplements QWidget::wheelEvent().

bool QAbstractSpinBox::wrapping() const

Returns whether stepping past one end goes round to the other. The default is false.

See also setWrapping().