即使焦点设置为true,返回键导航也不起作用

时间:2015-08-19 10:09:26

标签: android qt focus

在我的Qt Android应用程序中,我将菜单从菜单推送到StackView:

import QtQuick 2.0
import QtQuick.Controls 1.0

ApplicationWindow
{
    menuBar: MenuBar
    {
        Menu
        {
            title: qsTr("Menu")
            MenuItem
            {
                text: qsTr("Push page")
                onTriggered: stackView.push("qrc:/qml/SecondPage.qml")
            }
        }
    }

    StackView
    {
        id: stackView
        anchors.fill: parent
        // Implements back key navigation
        focus: true

        initialItem: FirstPage
        {
            width: parent.width
            height: parent.height
        }
    }
}

SecondPage.qml:

import QtQuick 2.0
import QtQuick.Controls 1.0

Item
{
    width: parent.width
    height: parent.height
    // focus: true

    Keys.onBackPressed: stackView.pop()

    Label
    {
        anchors.centerIn: parent
        text:  "Some text"
        font.pointSize: 32
        color: "gray"
    }
}

即使后退键退出整个应用程序。我尝试将focus: true添加到注释掉的位置并在event.accepted = true中调用Keys.onBackPressed。为什么忽略后退按键?

1 个答案:

答案 0 :(得分:2)

我应该将pop语句放入StackView本身,而不是放入子页面:

StackView
{
    id: stackView
    anchors.fill: parent
    // Implements back key navigation
    focus: true

    initialItem: FirstPage
    {
        width: parent.width
        height: parent.height
    }

    Keys.onBackPressed: pop()
}