即使焦点设置为true返回键导航不起作用 [英] Back key navigation doesn't work even though focus is set to true
本文介绍了即使焦点设置为true返回键导航不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的Qt Android应用我的推项目从菜单到StackView:
In my Qt Android app I push an Item from the menu to the 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:
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"
}
}
虽然,返回键退出整个应用程序。我尝试添加重点:真正的
到它是在<$ C $注释掉并调用 event.accepted = TRUE
C> Keys.onBack pressed 。为什么返回键preSS忽略?
Even though, back key exits the whole app. I tried adding focus: true
to where it is commented out and calling event.accepted = true
in Keys.onBackPressed
. Why is the back key press ignored?
推荐答案
我应该把弹出
语句到 StackView
本身,而不是成为一个子页面:
I should've put the pop
statement into the StackView
itself, not into a child page:
StackView
{
id: stackView
anchors.fill: parent
// Implements back key navigation
focus: true
initialItem: FirstPage
{
width: parent.width
height: parent.height
}
Keys.onBackPressed: pop()
}
这篇关于即使焦点设置为true返回键导航不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文