Keyboard focus. Bug in the documentation?
-
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'
}
}
}
}@- There are not unique ids (myText, keyHandler)
- 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.
-
you can log a bug for this at "http://bugreports.qt.nokia.com":http://bugreports.qt.nokia.com
-
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.