0
votes

I have an Item with signals and functions.
Now I encapsulate this Item with a FocusScope and e.g. bind some Item properties with an alias to the FocusScope. But how can I now use Item functions and signals?

Example:

FocusScope {
    property alias color: box.color

    Item {
        id: myBox
        anchors.fill: parent

        signal colorChanged()

        Rectangle {
            id: box
            width: parent.width
            height: parent.height
            anchors.centerIn: parent
            color: "red"
        }

        // some more code e.g. to emit the signal
    }
}

When I now create one of these FocusScopes I can't access the signal of the Item.

When using FocusScopes, do I really have to implement wrapper for everything? Or should I just replace the Item with the FocusScope?

1

1 Answers

1
votes

I think its better to replace item with FocusScope, i don't see if Item is serving any purpose here.

You can modify you code like below.

FocusScope {
    property alias color: box.color
    signal colorChanged()

    Rectangle {
        id: box
        width: parent.width
        height: parent.height
        anchors.centerIn: parent
        color: "red"
    }
    // some more code e.g. to emit the signal
}

If you want to use, Item under FocusScope, then you will need to define signal and functions under FocusScope.