diff --git a/spyder/plugins/shortcuts/widgets/table.py b/spyder/plugins/shortcuts/widgets/table.py index 55c59df3a7b..7371e6111e8 100644 --- a/spyder/plugins/shortcuts/widgets/table.py +++ b/spyder/plugins/shortcuts/widgets/table.py @@ -17,7 +17,7 @@ from qtpy.QtWidgets import (QAbstractItemView, QApplication, QDialog, QGridLayout, QHBoxLayout, QKeySequenceEdit, QLabel, QLineEdit, QMessageBox, QPushButton, - QSpacerItem, QTableView, QVBoxLayout) + QSpacerItem, QVBoxLayout) # Local imports from spyder.api.translations import _ @@ -25,10 +25,8 @@ from spyder.utils.icon_manager import ima from spyder.utils.qthelpers import create_toolbutton from spyder.utils.stringmatching import get_search_regex, get_search_scores -from spyder.widgets.helperwidgets import (VALID_FINDER_CHARS, - CustomSortFilterProxy, - HelperToolButton, - HTMLDelegate) +from spyder.widgets.helperwidgets import ( + HelperToolButton, HTMLDelegate, HoverRowsTableView, VALID_FINDER_CHARS) # Valid shortcut keys @@ -653,10 +651,10 @@ def reset(self): self.endResetModel() -class ShortcutsTable(QTableView): - def __init__(self, - parent=None, text_color=None, text_color_highlight=None): - QTableView.__init__(self, parent) +class ShortcutsTable(HoverRowsTableView): + def __init__(self, parent=None, text_color=None, + text_color_highlight=None): + HoverRowsTableView.__init__(self, parent) self._parent = parent self.finder = None self.shortcut_data = None @@ -675,8 +673,7 @@ def __init__(self, self.setModel(self.proxy_model) self.hideColumn(SEARCH_SCORE) - self.setItemDelegateForColumn(NAME, HTMLDelegate(self, margin=9)) - self.setItemDelegateForColumn(CONTEXT, HTMLDelegate(self, margin=9)) + self.setItemDelegate(HTMLDelegate(self, margin=9)) self.setSelectionBehavior(QAbstractItemView.SelectRows) self.setSelectionMode(QAbstractItemView.SingleSelection) self.setSortingEnabled(True) @@ -685,6 +682,10 @@ def __init__(self, self.verticalHeader().hide() + self.sig_hover_index_changed.connect( + self.itemDelegate().on_hover_index_changed + ) + def set_shortcut_data(self, shortcut_data): """ Shortcut data comes from the registration of actions on the main @@ -783,7 +784,7 @@ def save_shortcuts(self): def show_editor(self): """Create, setup and display the shortcut editor dialog.""" index = self.proxy_model.mapToSource(self.currentIndex()) - row, column = index.row(), index.column() + row = index.row() shortcuts = self.source_model.shortcuts context = shortcuts[row].context name = shortcuts[row].name diff --git a/spyder/widgets/helperwidgets.py b/spyder/widgets/helperwidgets.py index 8e2e99b395f..9f1f854cd62 100644 --- a/spyder/widgets/helperwidgets.py +++ b/spyder/widgets/helperwidgets.py @@ -157,6 +157,9 @@ def paint(self, painter, option, index): else options.widget.style()) options.text = "" + # This paints the entire row associated to the delegate when it's + # hovered and the table that holds it informs it what's the current + # row (see HoverRowsTableView for an example). if index.row() == self._hovered_row: painter.fillRect( options.rect, QColor(QStylePalette.COLOR_BACKGROUND_3)