diff options
author | Ruslan Kabatsayev <b7.10110111@gmail.com> | 2023-03-14 22:55:08 +0400 |
---|---|---|
committer | Ruslan Kabatsayev <b7.10110111@gmail.com> | 2023-03-14 22:55:08 +0400 |
commit | e7b25271450d60bd21205fca36fac21064002542 (patch) | |
tree | c53f75215429eb11958fd89206a3058e277df400 | |
parent | 8f5a783da05cafe57b7436b495ff74d38aa47451 (diff) |
Prevent Enter/Return keys unexpectedly clicking buttons in View dialogui/fov
-rw-r--r-- | src/gui/ViewDialog.cpp | 12 | ||||
-rw-r--r-- | src/gui/ViewDialog.hpp | 1 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/gui/ViewDialog.cpp b/src/gui/ViewDialog.cpp index ac73743a48..a24d4644f6 100644 --- a/src/gui/ViewDialog.cpp +++ b/src/gui/ViewDialog.cpp @@ -134,6 +134,8 @@ void ViewDialog::connectGroupBox(QGroupBox* groupBox, const QString& actionId) void ViewDialog::createDialogContent() { ui->setupUi(dialog); + dialog->installEventFilter(this); + StelApp *app = &StelApp::getInstance(); connect(app, SIGNAL(languageChanged()), this, SLOT(retranslate())); // Set the Sky tab activated by default @@ -566,6 +568,16 @@ void ViewDialog::createDialogContent() }); } +bool ViewDialog::eventFilter(QObject* object, QEvent* event) +{ + if (object != dialog || event->type() != QEvent::KeyPress) + return false; + const auto keyEvent = static_cast<QKeyEvent*>(event); + if (keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return) + return true; // Prevent these keys pressing buttons when focus is not on the buttons + return false; +} + void ViewDialog::setDisplayFormatForSpins(bool flagDecimalDegrees) { int places = 0; diff --git a/src/gui/ViewDialog.hpp b/src/gui/ViewDialog.hpp index bafb6c017d..645b46f650 100644 --- a/src/gui/ViewDialog.hpp +++ b/src/gui/ViewDialog.hpp @@ -52,6 +52,7 @@ protected: Ui_viewDialogForm* ui; //! Initialize the dialog widgets and connect the signals/slots void createDialogContent() override; + bool eventFilter(QObject* object, QEvent* event) override; private slots: void populateLists(); void populateToolTips(); |