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

Executing the snippet in the FocusScope documentation yields a different result

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.6.0
    • None

    Description

      Documentation link : https://doc.qt.io/qt-6/qtquick-input-focus.html#acquiring-focus-and-focus-scopes

      In the documentation, there are code snippets like this:

       

      //Window code that imports MyWidget
      Rectangle {
          id: window
          color: "white"; width: 240; height: 150    
        Column {
              anchors.centerIn: parent; spacing: 15        
              MyWidget {
                  focus: true             //set this MyWidget to receive the focus
                  color: "lightblue"
              }
              MyWidget {
                  color: "palegreen"
              }
          }
      } 
       // MyWidget.qml
      import QtQuick
      Rectangle {     
          id: widget     
          color: "lightsteelblue"; width: 175; height: 25; radius: 10; antialiasing: true     Text { id: label; anchors.centerIn: parent}     
          focus: true     
          Keys.onPressed: (event)=> {         
              if (event.key == Qt.Key_A)             
                  label.text = 'Key A was pressed'         
              else if (event.key == Qt.Key_B)             
                 label.text = 'Key B was pressed'         
              else if (event.key == Qt.Key_C)             
                 label.text = 'Key C was pressed'    
          } 
      }
      

       

      And according to the documentation, they are supposed to work like this; giving a focus to the last MyWidget.

       

      I copied and pasted the snippets and ran the code, then pressing the key A got me this result:

      The key focus is on the first MyWidget where it's supposed to be on the second, according to the documentation.

      I attached the project. This was built with Qt 6.6.0 Desktop MinGW64.

      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
            mikio_hirai Mikio Hirai
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes