Reputation: 233
I can't find any solution for this.I have an dialog which has an TextArea and Ok and close buttons.When I opened the dialog , Then close it. Back button is not working on Android. Why ? My code is :
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)
.......
......
Upvotes: 1
Views: 1371
Reputation: 735
I just ran into the very same problem myself today. In my app, I want to use a dialog with a TextField to let the user edit the title of some items.
The issue using Dialog in QML seems to be that even after the dialog is closed, it retains keyboard focus and hence captures the back button as well.
For me, the solution was to ensure that after the dialog has been closed (i.e. its visible
property is set to false
), active keyboard focus is handed back to the "main window":
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
}
}
}
Upvotes: 1