【问题标题】:FocusScope and "focus" property of child elements inside a Row element行元素内子元素的 FocusScope 和“焦点”属性
【发布时间】:2012-10-09 13:50:43
【问题描述】:

FocusScope 仅适用于子元素的“焦点”属性,还是也考虑大子元素的“焦点”属性。

即在下面的代码中,由于 Rectangle 元素不是 FocusScope 的直接子元素,在设置焦点时是否会考虑在内。

import QtQuick 1.1

FocusScope {
    width: 100
    height: 66
    Row {
        Rectangle {
            width: 100
            height: 62
            focus: true
            color: "red"
            Keys.onPressed: {
                console.log("hello")    
            }
        }
    }
}

根据程序的输出,看起来 FocusScope 在设置焦点时考虑了 Rectangle 元素。此功能未记录在案。

来自http://qt-project.org/doc/qt-4.8/qdeclarativefocus.html#qmlfocus Qt 文档 "在每个焦点范围内,一个元素可能会将 Item::focus 设置为 true。如果多个 Item 设置了焦点属性,则设置焦点的最后一个元素将具有焦点,其他元素未设置,类似于当没有焦点范围时。”

目前尚不清楚 FocusScope 是否考虑了孙子(childrens of childrens)的“焦点”属性。

【问题讨论】:

  • 它肯定会考虑到孙子和孙子(直到它满足另一个焦点范围),这是设计使然(至少我对此有 99.99% 的把握)。但是 QML 1 中的焦点是错误的(尤其是关于绑定到 focusactiveFocus),并且为 QML 2 重做,iirc;当心:)

标签: qt qml


【解决方案1】:

focus 属性告诉当FocusScope 将获得activeFocus 时哪个项目将成为焦点,因为你不应该有多个带有focus: true; 的项目,但它没有无论item在FocusScope中嵌套多深,总是有一个且只有一个focused 'end' item,如果没有被focused item使用,他所有的父母都可以收到key事件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多