From 3ae6b601a24082c825ed234fd7378c09d8d7ad9b Mon Sep 17 00:00:00 2001 From: John Jones-Steele <82226755+jjjoness@users.noreply.github.com> Date: Fri, 10 Dec 2021 22:34:41 +0000 Subject: [PATCH] Focus issue in editor settings menu #3921 (#6296) * Changes to fix DCO Signed-off-by: John Jones-Steele <82226755+jjjoness@users.noreply.github.com> * Moved the keyEvent to a helper function for ease of testing Signed-off-by: John Jones-Steele <82226755+jjjoness@users.noreply.github.com> * Split definition and declaration of WidgetHandleKeyPressEvent Signed-off-by: John Jones-Steele <82226755+jjjoness@users.noreply.github.com> --- Code/Editor/EditorPreferencesDialog.cpp | 25 +++++++++++++++++++++++++ Code/Editor/EditorPreferencesDialog.h | 3 +++ 2 files changed, 28 insertions(+) diff --git a/Code/Editor/EditorPreferencesDialog.cpp b/Code/Editor/EditorPreferencesDialog.cpp index a1859b0f14..665daf52a8 100644 --- a/Code/Editor/EditorPreferencesDialog.cpp +++ b/Code/Editor/EditorPreferencesDialog.cpp @@ -112,6 +112,31 @@ void EditorPreferencesDialog::showEvent(QShowEvent* event) QDialog::showEvent(event); } +void WidgetHandleKeyPressEvent(QWidget* widget, QKeyEvent* event) +{ + // If the enter key is pressed during any text input, the dialog box will close + // making it inconvenient to do multiple edits. This routine captures the + // Key_Enter or Key_Return and clears the focus to give a visible cue that + // editing of that field has finished and then doesn't propogate it. + if (event->key() != Qt::Key::Key_Enter && event->key() != Qt::Key::Key_Return) + { + QApplication::sendEvent(widget, event); + } + else + { + if (QWidget* editWidget = QApplication::focusWidget()) + { + editWidget->clearFocus(); + } + } +} + + +void EditorPreferencesDialog::keyPressEvent(QKeyEvent* event) +{ + WidgetHandleKeyPressEvent(this, event); +} + void EditorPreferencesDialog::OnTreeCurrentItemChanged() { QTreeWidgetItem* currentItem = ui->pageTree->currentItem(); diff --git a/Code/Editor/EditorPreferencesDialog.h b/Code/Editor/EditorPreferencesDialog.h index 64f44d7ab5..a3f05ad00d 100644 --- a/Code/Editor/EditorPreferencesDialog.h +++ b/Code/Editor/EditorPreferencesDialog.h @@ -19,6 +19,8 @@ namespace Ui class EditorPreferencesTreeWidgetItem; +void WidgetHandleKeyPressEvent(QWidget* widget, QKeyEvent* event); + class EditorPreferencesDialog : public QDialog , public AzToolsFramework::IPropertyEditorNotify @@ -36,6 +38,7 @@ public: protected: void showEvent(QShowEvent* event) override; + void keyPressEvent(QKeyEvent* event) override; private: void CreateImages();