Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Keyboard focus. Bug in the documentation?

    QML and Qt Quick
    2
    3
    1996
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      kibsoft last edited by

      Hi there! I've read "Keyboard Focus in QML" in the documentation and noticed several bugs (or not).

      There is an example:
      @Rectangle {
      color: "red"; width: 240; height: 55
      Rectangle {
      color: "lightsteelblue"; width: 240; height: 25
      Text { id: myText }
      Item {
      id: keyHandler
      focus: true
      Keys.onPressed: {
      if (event.key == Qt.Key_A)
      myText.text = 'Key A was pressed'
      else if (event.key == Qt.Key_B)
      myText.text = 'Key B was pressed'
      else if (event.key == Qt.Key_C)
      myText.text = 'Key C was pressed'
      }
      }
      }
      Rectangle {
      y: 30; focus: true
      color: "lightsteelblue"; width: 240; height: 25
      Text { id: myText }
      Item {
      id: keyHandler
      focus: true
      Keys.onPressed: {
      if (event.key == Qt.Key_A)
      myText.text = 'Key A was pressed'
      else if (event.key == Qt.Key_B)
      myText.text = 'Key B was pressed'
      else if (event.key == Qt.Key_C)
      myText.text = 'Key C was pressed'
      }
      }
      }
      }@

      1. There are not unique ids (myText, keyHandler)
      2. In the documentation written that focus should get first rectangle, but really focus is located on second one.

      From doc:

      bq. In this case the first appearance of the Item::focus property being set to true on line 4 is selected, and the value of Item::focus in the other two instances is reverted back to false. This is exactly the opposite of what was wanted!

      Thanks, Kirill.

      1 Reply Last reply Reply Quote 0
      • ?
        Guest last edited by

        you can log a bug for this at "http://bugreports.qt.nokia.com":http://bugreports.qt.nokia.com

        1 Reply Last reply Reply Quote 0
        • B
          blam last edited by

          The reason for the duplicated ids is indicated in the text below the example:

          [quote]
          The right hand side of the example shows the expanded code - the equivalent QML without the use of the component MyWidget.
          [/quote]

          The code is a theoretical expansion of the code in the left column; it's not real, usable code.

          With regards to the focus being on the second rectangle, the docs above the example code states:

          [quote]
          Here we create two instances of our previously defined component, and set the second one to have focus.
          [/quote]

          so this seems ok.

          However if there are problems in the docs they should definitely be reported at http://bugreports.qt.nokia.com.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post