todolist example: Make it easier to hide keyboard when finished editing

- Hide keyboard on Keys.onReturnPressed event in the TextField-s
- Add "Done" button to TextArea to mark editing as finished and hide
the keyboard in return

Done-with: Mitch Curtis <mitch.curtis@qt.io>
Pick-to: 6.4
Change-Id: I3351e5b3db356946b59b19c6f424153cbf2dbbb1
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
This commit is contained in:
Doris Verria 2022-09-13 00:07:42 +02:00
parent 8c6ff5a68d
commit db0716571c
2 changed files with 23 additions and 1 deletions

View File

@ -127,6 +127,11 @@ Page {
Layout.fillWidth: true
Layout.leftMargin: 10
Layout.rightMargin: 10
Keys.onReturnPressed: {
if (createProjectButton.enabled)
createProjectButton.clicked()
}
}
Button {

View File

@ -63,13 +63,14 @@ Page {
TextArea {
id: textArea
leftPadding: 15
rightPadding: 15
rightPadding: doneButton.width
bottomPadding: 10
topPadding: 10
font.pointSize: AppSettings.fontSize
placeholderText: qsTr("Write a note...")
text: root.projectNote
wrapMode: TextArea.Wrap
clip: true
Layout.fillWidth: true
Layout.preferredHeight: 80
@ -79,6 +80,16 @@ Page {
Database.updateProjectNote(root.projectId, text)
projectsModel.setProperty(projectIndex, "projectNote", textArea.text)
}
Button {
id: doneButton
text: qsTr("Done")
flat: true
visible: textArea.focus
onClicked: textArea.editingFinished()
anchors.right: parent.right
anchors.bottom: parent.bottom
}
}
ListView {
@ -186,6 +197,11 @@ Page {
placeholderText: qsTr("Enter task name")
font.pointSize: AppSettings.fontSize
Keys.onReturnPressed: {
if (addTaskButton.enabled)
addTaskButton.clicked()
}
Layout.fillWidth: true
Layout.leftMargin: 10
Layout.rightMargin: 10
@ -193,6 +209,7 @@ Page {
}
Button {
id: addTaskButton
text: qsTr("Add task")
flat: true
font.pointSize: AppSettings.fontSize