6.0.0-rc4Source

QDoubleSpinBox Class

The QDoubleSpinBox class lets the user pick a floating-point number by typing it or stepping with two buttons. More…

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

List of all members, including inherited members

Public Functions

QDoubleSpinBox(QWidget *parent = nullptr)
~QDoubleSpinBox()
doubleminimum() const
voidsetMinimum(double minimum)
doublemaximum() const
voidsetMaximum(double maximum)
voidsetRange(double minimum, double maximum)
doublevalue() const
doublesingleStep() const
voidsetSingleStep(double step)
intdecimals() const
voidsetDecimals(int decimals)
QStringprefix() const
voidsetPrefix(const QString &prefix)
QStringsuffix() const
voidsetSuffix(const QString &suffix)
QStringcleanText() const
virtual QStringtextFromValue(double value) const
virtual doublevalueFromText(const QString &text) const

Reimplemented Public Functions

voidstepBy(int steps)

Public Slots

voidsetValue(double value)

Signals

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

Reimplemented Protected Functions

StepEnabledstepEnabled() const

Detailed Description

A QDoubleSpinBox works like a QSpinBox, with a value that is a double shown with decimals() digits after the point. The value is rounded to those decimals:

QDoubleSpinBox *gain = new QDoubleSpinBox(window);
gain->setRange(0.0, 2.0);
gain->setSingleStep(0.05);
gain->setDecimals(2);
connect(gain, &QDoubleSpinBox::valueChanged, [](double value) { qDebug() << value; });

See also QSpinBox.

Differences from Qt

The number is written and read with a point, whatever the locale, and without group separators. There is no stepType(). textFromValue() and valueFromText() see the number without the prefix and the suffix.

Member Function Documentation

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

Constructs a spin box with the given parent. The range is 0.00 to 99.99, the value 0.00 and the single step 1.0.

[override] QDoubleSpinBox::~QDoubleSpinBox()

Destroys the spin box.

QString QDoubleSpinBox::cleanText() const

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

See also text().

int QDoubleSpinBox::decimals() const

Returns how many digits are shown after the point, 2 by default.

See also setDecimals().

double QDoubleSpinBox::maximum() const

Returns the largest value, 99.99 by default.

See also setMaximum() and setRange().

double QDoubleSpinBox::minimum() const

Returns the smallest value, 0.0 by default.

See also setMinimum() and setRange().

QString QDoubleSpinBox::prefix() const

Returns the text shown before the number.

See also setPrefix() and suffix().

void QDoubleSpinBox::setDecimals(int decimals)

Sets how many digits are shown after the point to decimals, from 0 to 15. The range and the value are rounded to them.

See also decimals().

void QDoubleSpinBox::setMaximum(double maximum)

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

See also maximum().

void QDoubleSpinBox::setMinimum(double minimum)

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

See also minimum().

void QDoubleSpinBox::setPrefix(const QString &prefix)

Sets the text shown before the number to prefix.

See also prefix().

void QDoubleSpinBox::setRange(double minimum, double maximum)

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

See also minimum() and maximum().

void QDoubleSpinBox::setSingleStep(double step)

Sets the step to step. A step that is not positive is ignored.

See also singleStep().

void QDoubleSpinBox::setSuffix(const QString &suffix)

Sets the text shown after the number to suffix.

See also suffix().

[slot] void QDoubleSpinBox::setValue(double value)

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

See also value().

double QDoubleSpinBox::singleStep() const

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

See also setSingleStep().

[override] void QDoubleSpinBox::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 QDoubleSpinBox::stepEnabled() const

Reimplements QAbstractSpinBox::stepEnabled().

QString QDoubleSpinBox::suffix() const

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

See also setSuffix() and prefix().

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

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

[virtual] QString QDoubleSpinBox::textFromValue(double value) const

Returns the text for value, without the prefix and the suffix: the number with decimals() digits after the point.

See also valueFromText().

double QDoubleSpinBox::value() const

Returns the value.

See also setValue().

[signal] void QDoubleSpinBox::valueChanged(double 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] double QDoubleSpinBox::valueFromText(const QString &text) const

Returns the value for text, which is the text between the prefix and the suffix.

See also textFromValue().