From 924351706fa6c629524d09a7e954961229903e4e Mon Sep 17 00:00:00 2001 From: Cheryl Sabella Date: Fri, 29 Dec 2017 18:20:04 -0500 Subject: [PATCH] issue 5426: Seg fault on shortcut preferences when using mouse --- spyder/plugins/shortcuts.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/spyder/plugins/shortcuts.py b/spyder/plugins/shortcuts.py index b2512ebdf21..8a2275fb347 100644 --- a/spyder/plugins/shortcuts.py +++ b/spyder/plugins/shortcuts.py @@ -16,7 +16,7 @@ from qtpy import PYQT5 from qtpy.compat import from_qvariant, to_qvariant from qtpy.QtCore import (QAbstractTableModel, QModelIndex, QRegExp, - QSortFilterProxyModel, Qt) + QSortFilterProxyModel, Qt, Slot) from qtpy.QtGui import (QKeySequence, QRegExpValidator) from qtpy.QtWidgets import (QAbstractItemView, QApplication, QDialog, QDialogButtonBox, QGridLayout, QHBoxLayout, QLabel, @@ -204,6 +204,24 @@ def __init__(self, parent, context, name, sequence, shortcuts): bbox.accepted.connect(self.accept) bbox.rejected.connect(self.reject) + @Slot() + def reject(self): + """Slot for rejected signal.""" + # Added for issue #5426. Due to the focusPolicy of Qt.NoFocus for the + # buttons, if the cancel button was clicked without first setting focus + # to the button, it would cause a seg fault crash. + self.button_cancel.setFocus() + super().reject() + + @Slot() + def accept(self): + """Slot for accepted signal.""" + # Added for issue #5426. Due to the focusPolicy of Qt.NoFocus for the + # buttons, if the ok button was clicked without first setting focus to + # the button, it would cause a seg fault crash. + self.button_ok.setFocus() + super().accept() + def keyPressEvent(self, e): """Qt override.""" key = e.key()