Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Make the list view of the file switcher look active at all times. #10683

Merged
merged 4 commits into from
Nov 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions spyder/widgets/switcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
Signal, Slot, QModelIndex)
from qtpy.QtGui import QStandardItem, QStandardItemModel, QTextDocument
from qtpy.QtWidgets import (QAbstractItemView, QApplication, QDialog,
QLineEdit, QListWidgetItem, QVBoxLayout, QListView)
QLineEdit, QListView, QListWidgetItem, QStyle,
QVBoxLayout)

# Local imports
from spyder.config.base import _
Expand Down Expand Up @@ -75,6 +76,20 @@ def eventFilter(self, src, e):
return super(KeyPressFilter, self).eventFilter(src, e)


class SwitcherDelegate(HTMLDelegate):
"""
This delegate allows the list view of the switcher to look like it has
the focus, even when its focus policy is set to Qt.NoFocus.
"""

def paint(self, painter, option, index):
"""
Override Qt method to force this delegate to look active at all times.
"""
option.state |= QStyle.State_Active
super(SwitcherDelegate, self).paint(painter, option, index)


class SwitcherBaseItem(QStandardItem):
"""Base List Item."""

Expand Down Expand Up @@ -528,7 +543,7 @@ def __init__(self, parent, help_text=None, item_styles=ITEM_STYLES,
self.edit.installEventFilter(self.filter)
self.edit.setPlaceholderText(help_text if help_text else '')
self.list.setMinimumWidth(self._MIN_WIDTH)
self.list.setItemDelegate(HTMLDelegate(self))
self.list.setItemDelegate(SwitcherDelegate(self))
self.list.setFocusPolicy(Qt.NoFocus)
self.list.setSelectionBehavior(self.list.SelectItems)
self.list.setSelectionMode(self.list.SingleSelection)
Expand Down