Details
-
Suggestion
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.6.2
-
e0c13e113 (dev), 11563e840 (6.5)
Description
https://doc.qt.io/qt-5.10/qml-qtquick-controls2-spinbox.html#details has an example of a spinbox that accepts floating point numbers, but it's not easy to extend. For example, it's not clear how to modify the code to allow entering small fractions (like 0.0001). Some answers on Stack Overflow come close, but it's hard to do it properly without entering C++.
For example, code based on this answer almost works, except that realValue is never written to, and can't be written to without a bi-directional binding:
import QtQuick 2.9 import QtQuick.Controls 2.2 import App 1.0 ApplicationWindow { width: 800 height: 800 visible: true SpinBox { id: control from: 0 editable: true stepSize: realStepSize * factor value: realValue * factor to : realTo * factor anchors.centerIn: parent property int decimals: 6 property real factor: Math.pow(10, decimals) property real realValue: 0.0 property real realFrom: 0.0 property real realTo: 100.0 property real realStepSize: .0001 onValueModified: print(realValue) validator: DoubleValidator { bottom: Math.min(control.from, control.to) * control.factor top: Math.max(control.from, control.to) * control.factor } textFromValue: function(value, locale) { return Number(value * 1.0 / control.factor).toLocaleString(locale, 'f', control.decimals) } valueFromText: function(text, locale) { return Number.fromLocaleString(locale, text) * factor } } }
It would be much nicer if we could offer something out of the box.
Attachments
Issue Links
- is duplicated by
-
QTBUG-99268 Make SpinBox more flexible to allow double precision values
- Closed
- is required for
-
QTBUG-74224 Mistake in the double SpinBox example
- Closed
- relates to
-
QTBUG-107056 Add a combined text and mouse input slider
- Open
Gerrit Reviews
For Gerrit Dashboard: QTBUG-67349 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
472200,7 | Doc: improve the SpinBox floating point example | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
477434,2 | Doc: improve the SpinBox floating point example | 6.5 | qt/qtdeclarative | Status: MERGED | +2 | 0 |
477490,1 | Doc: improve the SpinBox floating point example | tqtc/lts-6.2 | qt/tqtc-qtdeclarative | Status: ABANDONED | 0 | 0 |