与forceActiveFocus 相反的是什么?
我有这些 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
}
}
当我单击其中一个矩形时,它会获得焦点,而其他矩形会失去焦点。 这就是我想要的,好吧,但是当我单击空白区域、矩形之外以及项目中带有 id:container 的项目时,我希望一个矩形失去焦点?
我应该在哪里做什么?
I have these QML lines:
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
}
}
When i click one of the rectangle it gains focus and other lose focus.
This is what i want, ok, but i want one rectangle lose focus when i click white space, out of rectangles and in Item, item with id:container?
What should i do into where?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
专注的反面是专注于其他事情。
如果您不希望任何矩形具有任何焦点,只需调用
示例解决方案
The opposite of focus is focussing something else.
If you want no rectangle to have any focus just call
Sample solution
除非您使用 FocusScope 处理更复杂的图层,否则您可以将 focus 设置为 false:
Unless you're dealing with more complicate layers using FocusScope's, you could just set focus to false: