2
votes

I want to set the activeFocus for a FocusScope by clicking anywhere within an Item. Is there a way to achieve this without having a MouseArea over the entire Item? Because it would have to overlay all elements within the Item, making them unclickable.

I'm pretty new to QtQuick/QML and have troubles understanding how to properly implement FocusScopes. I've read about propagating click signals, but couldn't get it to work.

Assuming I have something like this (no FocusScopes for readability):

Rectangle
{
    id: outerRectangle

    width: 1000
    height: 1000

    // various controls in here

    Rectangle
    {
        id: innerRectangle

        anchors.centerIn: parent

        width: 200
        height: 200

        // even more controls in here
    }
}

I want the outerRectangle to get the activeFocus when I click anywhere on the outerRectangle and vice-versa for the innerRectangle. But all controls on both Rectangles still have to work properly. How can I achieve this?

1
MouseArea can be set to a different z level so that it does not overlay other controls. Apart from that I don't know if you already read this but it could be of interest. Also take in account this example. Hope it helps.BaCaRoZzo
Setting the Z doesn't help, sadly. As soon as the MouseArea is below another control, it won't register the click anymore.i know nothing

1 Answers

0
votes

Surround your Item with FocusScope:

FocusScope {
   Item {
       focus: true
   }
}

See Qt Doc