Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.6.0 Alpha
-
None
-
cf67efa1ea63fe11504799b9bb2329f70d99c525
Description
I created time editor using custom contentItem, that converts text in format "hh:mm:ss" to Date and set spinbox value as seconds (spinbox has int as value, not int64, so it cannot contain msecs). It is done in onEditingFinished handler. But after that, spinbox set it's value to 0! I found, that it is done in QQuickSpinBoxPrivate::updateValue() which called after spinbox lose active focus and it takes from contentItem property "text" and convert it to int, which produces 0.
I solved this problem using wrapper around content item and set it's text property instead of spinbox value, but this looks like a hack.
Example of workaround:
SpinBox { id: timeSpinBox property var currentDate: new Date() contentItem: FocusScope { id: wrapper property string text implicitWidth: textInput.implicitWidth implicitHeight: textInput.implicitHeight TextInput { id: textInput text: new Date(timeSpinBox.value * 1000).toLocaleTimeString(Qt.locale(), "hh:mm:ss") focus: true horizontalAlignment: Qt.AlignHCenter verticalAlignment: Qt.AlignVCenter onEditingFinished: { wrapper.text = Date.fromLocaleString(Qt.locale(), "%1 %2".arg(Qt.formatDate(currentDate, Qt.ISODate)).arg(text), "yyyy-MM-dd hh:mm:ss").valueOf() / 1000 } } } }