From 16cc60587fdfccf4029343e0699a39d904af93f6 Mon Sep 17 00:00:00 2001 From: guangong7628 Date: Tue, 23 Apr 2019 15:56:30 +0800 Subject: [PATCH] UI: Fix unable to escape when renaming scene Fixes https://obsproject.com/mantis/view.php?id=1443 --- UI/window-basic-main.cpp | 14 ++++++++++++++ UI/window-basic-main.hpp | 3 +++ 2 files changed, 17 insertions(+) diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index f3e68aae0..2b2327c91 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -7290,3 +7290,17 @@ void SceneRenameDelegate::setEditorData(QWidget *editor, if (lineEdit) lineEdit->selectAll(); } + +bool SceneRenameDelegate::eventFilter(QObject *editor, QEvent *event) +{ + if (event->type() == QEvent::KeyPress) { + QKeyEvent *keyEvent = static_cast(event); + if (keyEvent->key() == Qt::Key_Escape) { + QLineEdit *lineEdit = qobject_cast(editor); + if (lineEdit) + lineEdit->undo(); + } + } + + return QStyledItemDelegate::eventFilter(editor, event); +} diff --git a/UI/window-basic-main.hpp b/UI/window-basic-main.hpp index a94215341..849641d53 100644 --- a/UI/window-basic-main.hpp +++ b/UI/window-basic-main.hpp @@ -830,4 +830,7 @@ public: SceneRenameDelegate(QObject *parent); virtual void setEditorData(QWidget *editor, const QModelIndex &index) const override; + +protected: + virtual bool eventFilter(QObject *editor, QEvent *event) override; };