Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Keyboard focus. Bug in the documentation?
QtWS25 Last Chance

Keyboard focus. Bug in the documentation?

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 2.2k Views
  • 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 Offline
    K Offline
    kibsoft
    wrote on last edited by
    #1

    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
    0
    • ? This user is from outside of this forum
      ? This user is from outside of this forum
      Guest
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • B Offline
        B Offline
        blam
        wrote on last edited by
        #3

        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
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved