maxLibQt
maxLibQt::controls::MLDoubleSpinBox Class Reference

MLDoubleSpinBox is a drop-in replacement for QtQuick Controls 2 SpinBox which can handle double-precision numbers and long integers. More...

Inherits Control.

Inherited by maxLibQt::controls::MLHexSpinBox.

Properties

bool acceptableInput
 Indicates if input is valid (it would be nicer if the validator would expose an "isValid" prop/method!). More...
 
real botValue
 The effective minimum value. More...
 
int buttonRepeatDelay
 Milliseconds to delay before held +/- button repeat is activated. More...
 
int buttonRepeatInterval
 +/- button repeat interval while held (in milliseconds). More...
 
string cleanText
 Holds the text of the spin box excluding any prefix, suffix, or leading or trailing whitespace. More...
 
int decimals
 Desired precision. More...
 
string displayText
 
QtObject doubleValidator
 Default numeric validator, strictly enforces notation type, does not allow for custom inputMask with non-numeric components. More...
 
bool editable
 
double from
 
string inputMask
 Input mask for the text edit control (. More...
 
bool inputMethodComposing
 
int inputMethodHints
 
int notation
 For validator and text formatting. More...
 
int pageSteps
 How many steps in a "page" step (PAGE UP/DOWN keys or CTRL-Wheel). More...
 
string prefix
 Optional string to display before the value. More...
 
QtObject regExpValidator
 This is an experimental validator using a RegExp instead of numerical validation (which we do anyway). More...
 
bool selectByMouse
 Whether to allow selection of text (bound to the text editor of the spinbox control). More...
 
bool showGroupSeparator
 Whether to format numbers with the thousands separator visible (using current locale if useLocaleFormat is true). More...
 
SpinBox spinBoxItem
 The SpinBox item. More...
 
double stepSize
 
string suffix
 Optional string to display after the value. More...
 
Item textInputItem
 Use the "native" text editor of the SpinBox to preserve look/feel. If you use a custom SpinBox, you may need to set this property also. If defined, it must have a text property. More...
 
double to
 
real topValue
 The effective maximum value. More...
 
bool trimExtraZeros
 Whether to remove trailing zeros from decimals. More...
 
bool useLocaleFormat
 Whether to format numbers according to the current locale. More...
 
QtObject validator
 There are 2 validators available, see notes for each below. More...
 
double value
 
bool wrap
 

Public Member Functions

void decrease ()
 Decrement value by one stepSize. More...
 
void doubleValidationRegEx ()
 Return a RegExp object to validate numeric entry according to the current formatting & locale specs and accounting for any prefix/suffix. More...
 
void escapeInputMaskChars (string)
 Make string safe for use in Qt input mask as a literal. More...
 
void escapeRegExpChars (string)
 Make string safe for use in RegExp as a literal. More...
 
void getCleanText (text, locale)
 Return text stripped of any prefix or suffix and trimmed. More...
 
void increase ()
 Increment value by one stepSize. More...
 
bool setValue (real newValue, bool noWrap, bool notModified)
 Set the spin box value to newValue. More...
 
void stepBy (int steps, bool noWrap)
 Adjust value by number of steps. More...
 
void textFromValue (value, locale)
 Reimplimented from SpinBox. More...
 
void valueFromText (text, locale)
 Reimplimented from SpinBox. More...
 

Signals

void valueModified ()
 Mimic SpinBox API (interactive change only, NOT emitted if value property is set directly). More...
 

Detailed Description

MLDoubleSpinBox is a drop-in replacement for QtQuick Controls 2 SpinBox which can handle double-precision numbers and long integers.

Since
1.0
Supports SpinBox API of Controls v2.4 (Qt 5.11) but can be used with any version of QtQuick Controls 2 (Qt v5.2+).

The possible value range is defined by ECMAScript Number limits: +/- Number.MAX_VALUE for reals and between Number.MIN_SAFE_INTEGER and Number.MAX_SAFE_INTEGER for integers. This includes being able to handle unsigned 32b ints, something the base SpinBox can't do.

It has mostly the same properties, methods, and signal as SpinBox, except the value/from/to/stepSize properties are doubles. The only exception are the up and down group, which could be accessed directly via spinBoxItem. It also has a number of other custom properties not found in the default SpinBox (see inline documentation below).

Use the decimals property to control precision (default is 2).

In addition to the regular SpinBox controls (arrow keys/wheel-scroll), it reacts to Page Up/Down keys and CTRL-scroll for page-sized steps (see pageSteps property).

Individual property documentation can be found inline.

Note
About the prefix and suffix properties:
This SpinBox does add prefix and suffix properties, but it is not in an ideal way. Specifically, in an editable spin box, the cursor is not placed in the correct position for editing the actual value (user can start typing before/after/in middle of prefix/suffix). It does still work and will auto-correct properly after editing is finished, but it is a bit awkward at best. They do work nicely in a non-editable spin box.
To achieve proper prefix/suffix support, the best way would be to use a custom QValidator, just like the Controls 1 SpinBox does (or did... RIP). (search for QQuickSpinBoxValidator1) The other way is to use an input mask. Unfortunately Qt support for input masks is rather limited, and as a result one has to use a very specific mask (with the correct number of digits, notation type, localized, etc.). The number has to be typed/formatted exactly to the mask. This is not very user-friendly either, except in specific circumstances. Also the DoubleValidator does not work with input masks, so we need a custom validator in any case (see regExpValidator below).
The accompanying tests.qml file in this folder has an example of a customized spin box using an input mask with prefix and suffix. It is pretty generalized, but for standard notation only.

Definition at line 72 of file MLDoubleSpinBox.qml.

Property Documentation

◆ acceptableInput

bool maxLibQt::controls::MLDoubleSpinBox::acceptableInput

Indicates if input is valid (it would be nicer if the validator would expose an "isValid" prop/method!).

Remarks
This property is read-only

Definition at line 111 of file MLDoubleSpinBox.qml.

◆ botValue

real maxLibQt::controls::MLDoubleSpinBox::botValue

The effective minimum value.

Remarks
This property is read-only

Definition at line 115 of file MLDoubleSpinBox.qml.

◆ buttonRepeatDelay

int maxLibQt::controls::MLDoubleSpinBox::buttonRepeatDelay

Milliseconds to delay before held +/- button repeat is activated.

Definition at line 106 of file MLDoubleSpinBox.qml.

◆ buttonRepeatInterval

int maxLibQt::controls::MLDoubleSpinBox::buttonRepeatInterval

+/- button repeat interval while held (in milliseconds).

Definition at line 107 of file MLDoubleSpinBox.qml.

◆ cleanText

string maxLibQt::controls::MLDoubleSpinBox::cleanText

Holds the text of the spin box excluding any prefix, suffix, or leading or trailing whitespace.

Remarks
This property is read-only

Definition at line 109 of file MLDoubleSpinBox.qml.

◆ decimals

int maxLibQt::controls::MLDoubleSpinBox::decimals

Desired precision.

Definition at line 96 of file MLDoubleSpinBox.qml.

◆ displayText

string maxLibQt::controls::MLDoubleSpinBox::displayText
Remarks
This property is read-only

Definition at line 91 of file MLDoubleSpinBox.qml.

◆ doubleValidator

QtObject maxLibQt::controls::MLDoubleSpinBox::doubleValidator

Default numeric validator, strictly enforces notation type, does not allow for custom inputMask with non-numeric components.

Remarks
This property is read-only

Definition at line 124 of file MLDoubleSpinBox.qml.

◆ editable

bool maxLibQt::controls::MLDoubleSpinBox::editable

Definition at line 83 of file MLDoubleSpinBox.qml.

◆ from

double maxLibQt::controls::MLDoubleSpinBox::from

Definition at line 77 of file MLDoubleSpinBox.qml.

◆ inputMask

string maxLibQt::controls::MLDoubleSpinBox::inputMask

Input mask for the text edit control (.

See also
TextInput::inputMask).

Definition at line 98 of file MLDoubleSpinBox.qml.

◆ inputMethodComposing

bool maxLibQt::controls::MLDoubleSpinBox::inputMethodComposing
Remarks
This property is read-only

Definition at line 94 of file MLDoubleSpinBox.qml.

◆ inputMethodHints

int maxLibQt::controls::MLDoubleSpinBox::inputMethodHints

Definition at line 88 of file MLDoubleSpinBox.qml.

◆ notation

int maxLibQt::controls::MLDoubleSpinBox::notation

For validator and text formatting.

Definition at line 97 of file MLDoubleSpinBox.qml.

◆ pageSteps

int maxLibQt::controls::MLDoubleSpinBox::pageSteps

How many steps in a "page" step (PAGE UP/DOWN keys or CTRL-Wheel).

Definition at line 105 of file MLDoubleSpinBox.qml.

◆ prefix

string maxLibQt::controls::MLDoubleSpinBox::prefix

Optional string to display before the value.

See notes in the main comments above.

Definition at line 103 of file MLDoubleSpinBox.qml.

◆ regExpValidator

QtObject maxLibQt::controls::MLDoubleSpinBox::regExpValidator

This is an experimental validator using a RegExp instead of numerical validation (which we do anyway).

The advantage of using it is that:

  • It allows for scientific notation entry even if std. notation is specified (and vice versa) and will then re-format the entry as necessary after editing is finished.
  • Could also be used with a custom input mask, as demonstrated in tests.qml To use it, just set validator: regExpValidator
    Remarks
    This property is read-only

Definition at line 131 of file MLDoubleSpinBox.qml.

◆ selectByMouse

bool maxLibQt::controls::MLDoubleSpinBox::selectByMouse

Whether to allow selection of text (bound to the text editor of the spinbox control).

Definition at line 99 of file MLDoubleSpinBox.qml.

◆ showGroupSeparator

bool maxLibQt::controls::MLDoubleSpinBox::showGroupSeparator

Whether to format numbers with the thousands separator visible (using current locale if useLocaleFormat is true).

Definition at line 101 of file MLDoubleSpinBox.qml.

◆ spinBoxItem

SpinBox maxLibQt::controls::MLDoubleSpinBox::spinBoxItem

The SpinBox item.

To use a custom one, replace the contentItem with a class derived from Controls 2.x SpinBox. Or use any other contentItem (or even null) and (optionally) set the textInputItem to some Item with a text property for a custom display.

Remarks
This property is read-only

Definition at line 119 of file MLDoubleSpinBox.qml.

◆ stepSize

double maxLibQt::controls::MLDoubleSpinBox::stepSize

Definition at line 81 of file MLDoubleSpinBox.qml.

◆ suffix

string maxLibQt::controls::MLDoubleSpinBox::suffix

Optional string to display after the value.

See notes in the main comments above.

Definition at line 104 of file MLDoubleSpinBox.qml.

◆ textInputItem

Item maxLibQt::controls::MLDoubleSpinBox::textInputItem

Use the "native" text editor of the SpinBox to preserve look/feel. If you use a custom SpinBox, you may need to set this property also. If defined, it must have a text property.

Definition at line 121 of file MLDoubleSpinBox.qml.

◆ to

double maxLibQt::controls::MLDoubleSpinBox::to

Definition at line 79 of file MLDoubleSpinBox.qml.

◆ topValue

real maxLibQt::controls::MLDoubleSpinBox::topValue

The effective maximum value.

Remarks
This property is read-only

Definition at line 113 of file MLDoubleSpinBox.qml.

◆ trimExtraZeros

bool maxLibQt::controls::MLDoubleSpinBox::trimExtraZeros

Whether to remove trailing zeros from decimals.

Definition at line 102 of file MLDoubleSpinBox.qml.

◆ useLocaleFormat

bool maxLibQt::controls::MLDoubleSpinBox::useLocaleFormat

Whether to format numbers according to the current locale.

If false, use standard "C" format.

Definition at line 100 of file MLDoubleSpinBox.qml.

◆ validator

QtObject maxLibQt::controls::MLDoubleSpinBox::validator

There are 2 validators available, see notes for each below.

Definition at line 86 of file MLDoubleSpinBox.qml.

◆ value

double maxLibQt::controls::MLDoubleSpinBox::value

Definition at line 75 of file MLDoubleSpinBox.qml.

◆ wrap

bool maxLibQt::controls::MLDoubleSpinBox::wrap

Definition at line 85 of file MLDoubleSpinBox.qml.

Member Function Documentation

◆ decrease()

void maxLibQt::controls::MLDoubleSpinBox::decrease ( )

Decrement value by one stepSize.

◆ doubleValidationRegEx()

void maxLibQt::controls::MLDoubleSpinBox::doubleValidationRegEx ( )

Return a RegExp object to validate numeric entry according to the current formatting & locale specs and accounting for any prefix/suffix.

◆ escapeInputMaskChars()

void maxLibQt::controls::MLDoubleSpinBox::escapeInputMaskChars ( string  )

Make string safe for use in Qt input mask as a literal.

See also
QLineEdit::inputMask

◆ escapeRegExpChars()

void maxLibQt::controls::MLDoubleSpinBox::escapeRegExpChars ( string  )

Make string safe for use in RegExp as a literal.

◆ getCleanText()

void maxLibQt::controls::MLDoubleSpinBox::getCleanText ( text  ,
locale   
)

Return text stripped of any prefix or suffix and trimmed.

Same as cleanText property. Called by valueFromText() before other cleanup operations. Could be reimplemented for custom replacements.

◆ increase()

void maxLibQt::controls::MLDoubleSpinBox::increase ( )

Increment value by one stepSize.

◆ setValue()

bool maxLibQt::controls::MLDoubleSpinBox::setValue ( real  newValue,
bool  noWrap,
bool  notModified 
)

Set the spin box value to newValue.

This is generally preferable to setting the value spin box property directly, but not required.

Parameters
newValueThe value to set.
noWrap(optional) If true will prevent wrapping even if the spin box wrap property is true. Default is false.
notModified(optional) If true will prevent the valueModified() signal from being emitted. Default is false.
Returns
True if value was updated (that is, it did not equal the old value), false otherwise.

◆ stepBy()

void maxLibQt::controls::MLDoubleSpinBox::stepBy ( int  steps,
bool  noWrap 
)

Adjust value by number of steps.

(Each step size is determined by the spin box stepSize property.)

Parameters
stepsNumber of steps to adjust by. Can be negative to decrement the value.
noWrap(optional) If true will prevent wrapping even if the spin box wrap property is true. Default is false.

◆ textFromValue()

void maxLibQt::controls::MLDoubleSpinBox::textFromValue ( value  ,
locale   
)

Reimplimented from SpinBox.

◆ valueFromText()

void maxLibQt::controls::MLDoubleSpinBox::valueFromText ( text  ,
locale   
)

Reimplimented from SpinBox.

◆ valueModified

void maxLibQt::controls::MLDoubleSpinBox::valueModified ( )
signal

Mimic SpinBox API (interactive change only, NOT emitted if value property is set directly).