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

QML keyboard focus does not work from Components in Loader

    XMLWordPrintable

Details

    Description

      Hi,

      please consider the following to files:

      TestComponent.qml

      import Qt 4.7
      
      Rectangle {
          anchors.fill: parent
          width: 200
          height: 200
          color: "#f88"
          Component.onCompleted: {
              console.log("TestComponent.onCompleted()");
              console.log("  width:", width);
          }
      
          focus: true
      
          onWidthChanged: {
              console.log("width changed to:", width);
          }
      
          Keys.onPressed: {
              console.log("on Key pressed", event.key);
          }
      }
      

      and...

      BugKeyboard.qml :

      import Qt 4.7
      
      Rectangle {
          width: 200
          height: 200
      
          Component {
              id: testComponent
              TestComponent {}
          }
      
          Loader {
              id: mainLoader
              anchors.fill: parent
              sourceComponent:  testComponent
          }
      }
      

      Viewing BugLoader will print out the following console output:

      TestComponent.onCompleted()
        width: 200
      width changed to: 0
      width changed to: 0
      width changed to: 200
      width changed to: 640
      width changed to: 200
      

      I have two problems here:

      1. I can never trigger the Keys.onPressed hander of TestComponent when loaded as a Component.
      However it works just fine, when embedded like this:

      import Qt 4.7
      
      Rectangle {
          width: 200
          height: 200
      
          TestComponent {}
      }
      

      2. I'm stunned by the weird triggering of onWidthChanged(). Where does the 640 come from? Why setting this property so often. And most important: Why isn't the width set inCompleted if not set explicitly?

      Attachments

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

        Activity

          People

            aakenned Aaron Kennedy
            pixtur Thomas Mann
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes