2
votes

Does the FocusScope only works on child elements "focus" property or does it also considers the grand childerens "focus" property also.

i.e. In the below code, since the Rectangle element is not a direct child of FocusScope, will it take in to account while setting the focus.

import QtQuick 1.1

FocusScope {
    width: 100
    height: 66
    Row {
        Rectangle {
            width: 100
            height: 62
            focus: true
            color: "red"
            Keys.onPressed: {
                console.log("hello")    
            }
        }
    }
}

Based on the output of the program, it looks like FocusScope takes Rectangle element in to account while setting the focus. This feature is not documented.

From http://qt-project.org/doc/qt-4.8/qdeclarativefocus.html#qmlfocus Qt docs "Within each focus scope one element may have Item::focus set to true. If more than one Item has the focus property set, the last element to set the focus will have the focus and the others are unset, similar to when there are no focus scopes."

It is not clear whether the FocusScope considers the grandchildrens(childrens of childrens) "focus" property.

1
It will sure take grand- and grand-grand- children into account (until it meets another focus scope), that's by design (at least I'm 99,99% sure about that). But focus in QML 1 is buggy (esp. with regard to binding to either focus or activeFocus), and was redone for QML 2, iirc; beware :)mlvljr

1 Answers

4
votes

The focus property tells which item is going to take the focus when the FocusScope will gain the activeFocus, to you shouldn't have more than one item with focus: true; on it, but it doesn't matter how deeply the item is nested in the FocusScope, there is always one and only one focused 'end' item, and all his parents can receive the key event if not used by the focused item.