QT/QML,对话框打开后,返回按钮在Android上不工作?
我找不到任何解决方案。我有一个对话框,它有一个文本区域和“确定”和“关闭”按钮。当我打开对话框时,然后关闭它。“后退”按钮在Android上不起作用。为什么?我的代码是:QT/QML,对话框打开后,返回按钮在Android上不工作?,android,qt,qml,Android,Qt,Qml,我找不到任何解决方案。我有一个对话框,它有一个文本区域和“确定”和“关闭”按钮。当我打开对话框时,然后关闭它。“后退”按钮在Android上不起作用。为什么?我的代码是: Dialog { id: messagereject Connections { target:process ignoreUnknownSignals: true onSuccessrejectwo: { var t
Dialog {
id: messagereject
Connections
{
target:process
ignoreUnknownSignals: true
onSuccessrejectwo: {
var task=stackView.get(0).currenttask;
task.color="red";
task.enabled=false;
rejectreasontxt.text="";
}
}
contentItem:ColumnLayout {
id:rejectlay
Layout.preferredHeight: rejectheadertxt.height+rejectreasontxt.height+dp(30)
Layout.preferredWidth: rejectheadertxt.width+dp(100)
spacing: dp(10)
.......
......
今天我自己也遇到了同样的问题。在我的应用程序中,我想使用带有文本字段的对话框,让用户编辑某些项目的标题 在QML中使用对话框的问题似乎是,即使在对话框关闭后,它仍保留键盘焦点,因此也会捕获“后退”按钮 对我来说,解决方案是确保对话框关闭后(即其
可见
属性设置为假
),活动键盘焦点返回到“主窗口”:
只需打开一个
堆栈视图
,而不是对话框
。看起来Android在从Qt对话框返回时遇到了一些问题。没错。forceActiveFocus函数解决了这个问题
import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Dialogs 1.2
ApplicationWindow {
id: mainWindow
width: 200
height: 150
visible: true
FocusScope {
id: rootItem
anchors.fill: parent
Label {
id: label
text: qsTr("Hello World")
anchors.centerIn: parent
}
Button {
text: qsTr("Edit")
anchors {
right: parent.right
bottom: parent.bottom
margins: 10
}
onClicked: {
edit.text = label.text;
dialog.open();
// Let the TextField gain keyboard focus. This also
// means the main window no longer gets keyboard input
// so from here on input (including the back button)
// is handled by the dialog:
edit.forceActiveFocus();
}
}
}
Dialog {
id: dialog
standardButtons: StandardButton.Ok | StandardButton.Cancel
onAccepted: label.text = edit.text
onVisibleChanged: {
if (!visible) {
// Force some item in the main window (in our case the "root item")
// to gain active focus:
rootItem.forceActiveFocus();
}
}
TextField {
id: edit
}
}
}