• 2780阅读
  • 0回复

[提问]Loader动态加载组件时KeyNavigation异常问题 [复制链接]

上一主题 下一主题
离线zjhui2016
 

只看楼主 倒序阅读 楼主  发表于: 2016-12-20
下面QML代码,使用键盘TAB键,在控件间导航,第一次能够两个checkbox、两个button间正常导航,但第二次导航时,checkbox2就直接导航到button2了。这是为什么?



// main.qml

import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Dialogs 1.2

ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    Item {
        anchors.fill: parent
        Column {
            CheckBox {
                id: checkbox1
                text: "checkbox1"
                focus: true
                KeyNavigation.tab: checkbox2
            }
            CheckBox {
                id: checkbox2
                text: "checkbox2"
                focus: true
                KeyNavigation.tab: loadItem
            }
            Loader {
                id: loadItem
                width: 100
                height: 40
                source: "OtherItem.qml"
                focus: true
                KeyNavigation.tab: checkbox1
            }
        }
    }
}

// OtherItem.qml

import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Dialogs 1.2

Item {
    anchors.fill: parent
    Row {
        Button {
            id: button1
            text: "button1"
            focus: true
            KeyNavigation.tab:  button2
            Keys.onReturnPressed: {
                console.log("button1 enter");
            }
        }
        Button {
            id: button2
            text: "button2"
            focus: true

            Keys.onReturnPressed: {
                console.log("button2 enter");
            }
        }
    }
}
快速回复
限100 字节
 
上一个 下一个