gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 20:30:15 25 4
gpt4 key购买 nike

在我的 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/

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