Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-48989

SpinBox always converts value in contentItem as int

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.6.0 RC
    • 5.6.0 Alpha
    • Quick: Controls 2
    • 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
                  }
              }
          }
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            krnekit Nikita Krupenko
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes