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

Regression - QML State doesn't allow for Key.onPressed to work correctly

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P4: Low
    • None
    • 5.0.0 Beta 2
    • None
    • Ubuntu 12.04 Qt5 Beta 1
    • e03e870b7b4aac85e85b56655ccbc5d99c91053f

    Description

      If a item has the Key.onPressed implemented and then is overridden by PropertyChanges in a State, the Key.onPressed will fail on event variable with the following message:

      main.qml:88: ReferenceError: event is not defined

      The code works in Qt 4.8 and I think it worked in Qt5 Alpha.

      See the following example:

      import QtQuick 2.0
      
      Rectangle {
          id: mainRectangle
          width: 400
          height: 400
      
          Text {
              id: keyResultText
              anchors.top: parent
              anchors.horizontalCenter: parent.horizontalCenter
          }
      
          Rectangle {
              id: topRectangle
      
              anchors.centerIn: parent
              color: "lightgreen"
              width: 200
              height: 150
      
              Text {
                  id: textId
                  text: "Default State (Click to change)"
                  anchors.centerIn: parent
              }
      
              MouseArea {
                  id: stateChangeMouseArea
                  anchors.fill: parent
                  onClicked: {
                      mainRectangle.state = "Awesome State 3000"
                  }
              }
          }
      
          Rectangle {
              id: keyRectangle
      
              border.width: 1
      
              width: 200
              height: 100
      
              anchors.top: topRectangle.bottom
              anchors.horizontalCenter: topRectangle.horizontalCenter
              anchors.topMargin: 15
      
              focus: true
      
              Text {
                  id: textId2
                  text: "Press Enter"
              }
      
              Keys.onPressed: {
                  if(event.key === Qt.Key_Return) {
                      keyResultText.text = "Enter Pressed!"
                  }
              }
      
      
          }
      
          states: [
      
              State {
                  name: "Awesome State 3000"
      
                  PropertyChanges {
                      target: textId
                      text: "Awesome State 3000 (Click to change)"
                  }
      
                  PropertyChanges {
                      target: textId2
                      text: "Press Space (This will error!)"
                  }
      
                  PropertyChanges {
                      target: stateChangeMouseArea
                      onClicked: {
                          mainRectangle.state = ""
                      }
                  }
      
                  PropertyChanges {
                      target: keyRectangle
                      Keys.onPressed: {
                          if(event.key === Qt.Key_Space) {
                              keyResultText.text = "Enter Space!"
                          }
                      }
                  }
      
              }
      
          ]
      }
      

      Attachments

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

        Activity

          People

            frederik Frederik Gladhorn
            vpicaver Philip Schuchardt
            Votes:
            2 Vote for this issue
            Watchers:
            10 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes