android - 即使焦点设置为 true,后退键导航也不起作用

标签 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
        }
    }
}

第二页.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 添加到它被注释掉的位置,并在 Keys.onBackPressed 中调用 event.accepted = true。为什么后退键被忽略了?

最佳答案

我应该将 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()
}

关于android - 即使焦点设置为 true,后退键导航也不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32092532/

相关文章:

android - 自定义achart引擎饼图

android - 应用程序已在 android 模拟器中停止

android - 获取应用播放音频的详细信息

c++ - VTK中场景的旋转中心

c++ - 如何防止多次并行打开QFile

Delphi:TRadioButton的TabStop问题

android - Admob xml : the following classes could not be instantiated: - com. google.android.gms.ads.AdView

c++ - Qt找不到平台插件cocoa

java - 将焦点放在 JLayeredPane 中的 JPanel

jQuery:如何知道表格行何时失去焦点?