forceActiveFocus的反义词是什么?

mer*_*esi 5 qml

我有这些QML行:

Item {
    id:container
    Rectangle {
        id:rec1
        width:20; height:20; x:20; y:20
        color:"blue"
        MouseArea {
            onClicked:rec1.forceActiveFocus();
        }
        //bla bla
    }

    Rectangle {
        id:rec2
        width:20; height:20; x:200; y:200
        color:"red"
        MouseArea {
            onClicked:rec2.forceActiveFocus();
        }
        //bla bla
    }
}
Run Code Online (Sandbox Code Playgroud)

当我点击其中一个矩形时,它会获得焦点而其他焦点会失去焦点.这就是我想要的,好吧,但我想要一个矩形失去焦点当我点击白色空间,矩形和项目,项目ID:容器?

我该怎么办?

bla*_*raz 4

专注的反面是专注于其他事情。如果你不希望任何矩形有任何焦点,只需调用

container.forceActiveFocus()
Run Code Online (Sandbox Code Playgroud)

样品溶液

Rectangle {
    id: container
    width: 240
    height: 240
    color: activeFocus ? "black" : "white"

    MouseArea {
        z: 1
        anchors.fill: parent
        onClicked: container.forceActiveFocus();
    }

    Rectangle {
        id:rec1
        width:20; height:20; x:20; y:20
        z: 2
        color: activeFocus ? "blue" : "lightblue"
        MouseArea {
            anchors.fill: parent
            onClicked:rec1.forceActiveFocus();
        }
        //bla bla
    }

    Rectangle {
        id:rec2
        width:20; height:20; x:200; y:200
        color: activeFocus ? "red" : "lightsalmon"
        z: 2
        MouseArea {
            anchors.fill: parent
            onClicked:rec2.forceActiveFocus();
        }

        //bla bla
    }

}
Run Code Online (Sandbox Code Playgroud)