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

QMLLINT Fix Suggestion for SpinBox property textFromValue misleading

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.9
    • Active Qt
    • None

    Description

      When using QML linter with the default parameter, on a customized SpinBox with contentItem (see code below), then the linter posts a warning about the textFromValue being used. The use of the textFromValue property should be in line with our documentation, and, therefore, it shouldn't trigger a warning. The subsequent fix as a response to the linter warning may make the code worse (at least when done with Sonnet 4 LLM).

       

      Code analysed by linter:

      import QtQuick
      import QtQuick.Controls.Basic

      SpinBox {
          id: spinBox
          from: 0
          to: 100
          value: 50
          stepSize: 1
          
          width: 150
          height: 40
          
          background: Rectangle

      {         color: spinBox.enabled ? "white" : "#f0f0f0"         border.color: spinBox.activeFocus ? "#0078d4" : "#cccccc"         border.width: 1         radius: 4     }

          
          contentItem: TextInput

      {         text: spinBox.textFromValue(spinBox.value, spinBox.locale)         font.pixelSize: 14         color: spinBox.enabled ? "black" : "#666666"         horizontalAlignment: Qt.AlignHCenter         verticalAlignment: Qt.AlignVCenter         readOnly: !spinBox.editable         validator: spinBox.validator         inputMethodHints: Qt.ImhFormattedNumbersOnly     }

          
          up.indicator: Rectangle {
              x: spinBox.mirrored ? 0 : parent.width - width
              height: parent.height / 2
              width: 30
              color: spinBox.up.pressed ? "#e0e0e0" : (spinBox.up.hovered ? "#f5f5f5" : "transparent")
              border.color: "#cccccc"
              border.width: spinBox.up.pressed ? 1 : 0
              
              Text

      {             text: "▲"             font.pixelSize: 10             color: spinBox.enabled ? "black" : "#cccccc"             anchors.centerIn: parent         }

          }
          
          down.indicator: Rectangle {
              x: spinBox.mirrored ? 0 : parent.width - width
              y: parent.height / 2
              height: parent.height / 2
              width: 30
              color: spinBox.down.pressed ? "#e0e0e0" : (spinBox.down.hovered ? "#f5f5f5" : "transparent")
              border.color: "#cccccc"
              border.width: spinBox.down.pressed ? 1 : 0
              
              Text

      {             text: "▼"             font.pixelSize: 10             color: spinBox.enabled ? "black" : "#cccccc"             anchors.centerIn: parent         }

          }
      }

       

       

      Linter warning:

      Warning: /var/folders/7q/0ftm5_g54b91ck89ym4wjycr0000gp/T/tmpdy4vuuom.qml:22:23: Property "textFromValue" is a QJSValue property. It may or may not be a method. Use a regular Q_INVOKABLE instead. [use-proper-function]
              text: spinBox.textFromValue(spinBox.value, spinBox.locale)
                            ^^^^^^^^^^^^^

      Attachments

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

        Activity

          People

            owolff Oliver Wolff
            peter.schneider Peter Schneider
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes