6.0.0-rc4Source

QSpinBox Class

The QSpinBox class lets the user pick an integer by typing it or stepping with two buttons. More…

Header#include <QSpinBox>
CMaketarget_link_libraries(app PRIVATE Nt::Widgets)
ModuleNt Widgets C++ Classes
InheritsQAbstractSpinBox

List of all members, including inherited members

Public Functions

QSpinBox(QWidget *parent = nullptr)
~QSpinBox()
intminimum() const
voidsetMinimum(int minimum)
intmaximum() const
voidsetMaximum(int maximum)
voidsetRange(int minimum, int maximum)
intvalue() const
intsingleStep() const
voidsetSingleStep(int step)
QStringprefix() const
voidsetPrefix(const QString &prefix)
QStringsuffix() const
voidsetSuffix(const QString &suffix)
QStringcleanText() const

Reimplemented Public Functions

voidstepBy(int steps)

Public Slots

voidsetValue(int value)

Signals

voidvalueChanged(int value)
voidtextChanged(const QString &text)

Protected Functions

virtual QStringtextFromValue(int value) const
virtual intvalueFromText(const QString &text) const

Reimplemented Protected Functions

StepEnabledstepEnabled() const

Detailed Description

A spin box shows a number in a text that the user can edit, with a button to step up and one to step down. The arrow keys, Page Up and Page Down, and the mouse wheel step too. A prefix and a suffix, such as a unit, are shown around the number:

QSpinBox *size = new QSpinBox(window);
size->setRange(8, 72);
size->setSuffix(" pt");
connect(size, &QSpinBox::valueChanged, [](int value) { qDebug() << value; });

Spin boxes: plain, with a suffix and the keyboard focus, with a prefix, at the largest value, and disabled.

QSpinBox in the light color scheme

See also QDoubleSpinBox, QSlider and QLineEdit.

Differences from Qt

There is no displayIntegerBase() or stepType(). textFromValue() and valueFromText() see the number without the prefix and the suffix, and what the user types is checked by turning it into a value and back.

Member Function Documentation

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

Constructs a spin box with the given parent. The range is 0 to 99 and the value 0.

[override] QSpinBox::~QSpinBox()

Destroys the spin box.

QString QSpinBox::cleanText() const

Returns the number as text, without the prefix and the suffix.

See also text().

int QSpinBox::maximum() const

Returns the largest value, 99 by default.

See also setMaximum() and setRange().

int QSpinBox::minimum() const

Returns the smallest value, 0 by default.

See also setMinimum() and setRange().

QString QSpinBox::prefix() const

Returns the text shown before the number.

See also setPrefix() and suffix().

void QSpinBox::setMaximum(int maximum)

Sets the largest value to maximum. The smallest value falls to the same if it was larger.

See also maximum().

void QSpinBox::setMinimum(int minimum)

Sets the smallest value to minimum. The largest value grows to the same if it was smaller.

See also minimum().

void QSpinBox::setPrefix(const QString &prefix)

Sets the text shown before the number to prefix.

See also prefix().

void QSpinBox::setRange(int minimum, int maximum)

Sets the range of the spin box to minimum to maximum. If maximum is less than minimum, it is made equal. The value is brought into the range.

See also minimum() and maximum().

void QSpinBox::setSingleStep(int step)

Sets the step to step, at least 1.

See also singleStep().

void QSpinBox::setSuffix(const QString &suffix)

Sets the text shown after the number to suffix.

See also suffix().

[slot] void QSpinBox::setValue(int value)

Sets the value to value, brought into the range. Emits valueChanged() if the value changes.

See also value().

int QSpinBox::singleStep() const

Returns how much a step changes the value by, 1 by default.

See also setSingleStep().

[override] void QSpinBox::stepBy(int steps)

Reimplements QAbstractSpinBox::stepBy().

The value moves by steps times singleStep(). Past an end it stops there, or goes round to the other end if the spin box wraps.

[override, protected] StepEnabled QSpinBox::stepEnabled() const

Reimplements QAbstractSpinBox::stepEnabled().

QString QSpinBox::suffix() const

Returns the text shown after the number, such as a unit.

See also setSuffix() and prefix().

[signal] void QSpinBox::textChanged(const QString &text)

This signal is emitted when the value changes, with the text that shows it, prefix and suffix included.

[virtual, protected] QString QSpinBox::textFromValue(int value) const

Returns the text for value, without the prefix and the suffix. The default implementation writes the number in decimal; reimplement it to show the value in another way, together with valueFromText().

See also valueFromText().

int QSpinBox::value() const

Returns the value.

See also setValue().

[signal] void QSpinBox::valueChanged(int value)

This signal is emitted when the value changes to value, whether the user changed it by typing or with the buttons, or setValue() did.

[virtual, protected] int QSpinBox::valueFromText(const QString &text) const

Returns the value for text, which is the text between the prefix and the suffix. The default implementation reads a decimal number.

See also textFromValue().