gpt4 book ai didi

qt - 在QML中forceActiveFocus()vs focus = true

转载 作者:行者123 更新时间:2023-12-04 13:34:09 30 4
gpt4 key购买 nike

我阅读了有关以下内容的文档:

  • focus property
  • activeFocus property
  • forceActiveFocus() method
  • FocusScope object
  • and keyboard focus in QtQuick

  • 但尚不清楚何时应使用 forceActiveFocus()方法,而不是将 focus属性设置为true,反之亦然。

    最佳答案

    作为documentation states:

    For very simple cases simply setting the focus property is sometimes sufficient.


    如果获得 Itemfocus: true没有被可能没有焦点的 FocusScope包围,那么这种情况很简单。
    然后继续:

    > Within each focus scope one object may have Item::focus set to true. If more than one Item has the focus property set, the last type to set the focus will have the focus and the others are unset, similar to when there are no focus scopes.

    > When a focus scope receives active focus, the contained type with focus set (if any) also gets the active focus. If this type is also a FocusScope, the proxying behavior continues. Both the focus scope and the sub-focused item will have the activeFocus property set.


    从我们的学习中得知,如果设置 focus: true不足以作为 Item的后继者,那么设置 FocusScope是必须的,因为此 FocusScope将需要 activeFocus su,以使后继 Item可以接收 activeFocus。这是递归的,这意味着 FocusScope将需要具有 focus: true,并且可能的前身 FocusScope需要 activeFocus等等。导致某种焦点树
    该焦点树由 FocusScope的内部节点和 Item的叶子组成。 FocusScope也可能是一片叶子,但我不知道为什么要这么做。
    在这棵树中,每个 FocusScope最多可以有一个子节点( Item(叶)或 FocusScope(内部节点),具有 focus === true。遍历该树,沿着所有被遍历的节点都具有 focus === true的路径,被遍历的节点也具有 activeFocus === true。每个 FocusScope最多只能有一个带有 focus === true的子节点,只有一个这样的路径。
    Column {
    FocusScope {
    focus: false
    width: 100
    height: 100
    Text {
    focus: true
    text: 'has focus ' + focus + '\nhas activeFocus ' + activeFocus
    }
    }
    FocusScope {
    focus: true
    width: 100
    height: 100
    Text {
    focus: true
    text: 'has focus ' + focus + '\nhas activeFocus ' + activeFocus
    }
    }
    }
    这里我们有两个 FocusScope。两者都有一个带有 focus的子代,但是由于只有第二个 FocusScope本身具有 focus,因此它的子代具有 activeFocusforceActiveFocus()的使用遍历焦点树,并在路上将每个节点的 focus设置为 true,因此 Item的末尾带有 activeFocus

    关于qt - 在QML中forceActiveFocus()vs focus = true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43487731/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com