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

NumberAnimation doesn't complain when its target property is not a number

    XMLWordPrintable

Details

    Description

      The following code results in the Switch's handle becoming black, when the expected behaviour is (also) a warning that NumberAnimation can only animate numbers.

      Having this as a warning in qmllint would also be nice.

      import QtQuick
      import QtQuick.Controls
      import QtQuick.Layouts
      
      ApplicationWindow {
          width: 800
          height: 800
          visible: true
      
          Switch {
              id: control
              y: 100
              indicator: Rectangle {
                  id: indicator
                  x: control.leftPadding + (control.availableWidth - width) / 2
                  y: parent.height / 2 - height / 2
                  width: 52
                  height: 32
                  radius: height / 2
                  color: control.checked ? "pink" : "#444"
      
                  Rectangle {
                      id: handle
                      x: Math.max(offset, Math.min(parent.width - offset - width,
                          control.visualPosition * parent.width - (width / 2)))
                      y: (parent.height - height) / 2
                      width: normalSize * largestScale
                      height: normalSize * largestScale
                      radius: width / 2
                      color: control.checked
                             ? (control.hovered ? Qt.lighter("red") : "red")
                             : (control.hovered ? Qt.lighter("grey") : "grey")
                      scale: control.down ? 1 : (control.checked ? checkedSize / largestSize : normalSize / largestSize)
      
                      readonly property int offset: 2
                      readonly property real normalSize: !hasIcon ? 16 : checkedSize
                      readonly property real checkedSize: 24
                      readonly property real largestSize: 28
                      readonly property real largestScale: largestSize / normalSize
                      readonly property bool hasIcon: control.icon.name.length > 0
                          || control.icon.source.toString().length > 0
      
                      Behavior on x {
                          enabled: !control.pressed
                          SmoothedAnimation {
                              duration: 300
                          }
                      }
      
                      Behavior on scale {
                          NumberAnimation {
                              duration: 100
                          }
                      }
      
                      // Results in a black handle
                      Behavior on color {
                          NumberAnimation {
                              duration: 200
                          }
                      }
                  }
              }
          }
      }
      

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            mitch_curtis Mitch Curtis
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes