Browse Source

Merge pull request #1850 from guangong7628/renaming-scene

UI: Fix unable to escape when renaming scene
Jim 6 years ago
parent
commit
575f998fdd
2 changed files with 17 additions and 0 deletions
  1. 14 0
      UI/window-basic-main.cpp
  2. 3 0
      UI/window-basic-main.hpp

+ 14 - 0
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<QKeyEvent *>(event);
+		if (keyEvent->key() == Qt::Key_Escape) {
+			QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor);
+			if (lineEdit)
+				lineEdit->undo();
+		}
+	}
+
+	return QStyledItemDelegate::eventFilter(editor, event);
+}

+ 3 - 0
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;
 };