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> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
| Inherits | QAbstractSpinBox |
List of all members, including inherited members
Public Functions
| QDoubleSpinBox(QWidget *parent = nullptr) | |
| ~QDoubleSpinBox() | |
| double | minimum() const |
| void | setMinimum(double minimum) |
| double | maximum() const |
| void | setMaximum(double maximum) |
| void | setRange(double minimum, double maximum) |
| double | value() const |
| double | singleStep() const |
| void | setSingleStep(double step) |
| int | decimals() const |
| void | setDecimals(int decimals) |
| QString | prefix() const |
| void | setPrefix(const QString &prefix) |
| QString | suffix() const |
| void | setSuffix(const QString &suffix) |
| QString | cleanText() const |
| virtual QString | textFromValue(double value) const |
| virtual double | valueFromText(const QString &text) const |
Reimplemented Public Functions
| void | stepBy(int steps) |
Public Slots
| void | setValue(double value) |
Signals
| void | valueChanged(double value) |
| void | textChanged(const QString &text) |
Reimplemented Protected Functions
| StepEnabled | stepEnabled() 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
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.
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().
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().
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.
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().
void QDoubleSpinBox::textChanged(const QString &text)
This signal is emitted when the value changes, with the text that shows it, prefix and suffix included.
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().
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.
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().