How can I force my keyboard layout to display the "Next" button in QML ? ( Like in a standard HTML form ) I don't want to display a "OK" button ( which means that you're about to validate the form .. )
3 Answers
6
votes
You can use the EnterKey
attached property introduced in Qt 5.6:
import QtQuick 2.6
TextInput {
EnterKey.type: Qt.EnterKeyNext
}
1
votes
0
votes
I assumed you not used Qt Virtual Keyboard. So you can set action button type through EnterKey.type
attached property (available types are Go, Search, Send, Next,...).
Also you need to handle return button pressed signal to do what you want. For example, sending data. In your case you want just switch focus to next control.
import QtQuick 2.12
import QtQuick.Controls 1.12
Column {
TextField {
id: field1
KeyNavigation.tab: field2
activeFocusOnTab: true
Keys.onReturnPressed: KeyNavigation.tab.forceActiveFocus();
}
TextField {
id: field2
KeyNavigation.tab: field3
activeFocusOnTab: true
Keys.onReturnPressed: KeyNavigation.tab.forceActiveFocus();
}
TextField {
id: field3
KeyNavigation.tab: field1
activeFocusOnTab: true
Keys.onReturnPressed: KeyNavigation.tab.forceActiveFocus();
}
}
I handled returnPressed
signal to switch focus. Also I made it possible to switch using TAB
key for Desktop platforms.