Skip to content

Commit

Permalink
PaletteItemDelegate: Fix highlighted item foreground color
Browse files Browse the repository at this point in the history
  • Loading branch information
mborgerson committed Feb 13, 2025
1 parent 4a92418 commit bc30d22
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions angrmanagement/ui/dialogs/command_palette.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import TYPE_CHECKING, Any

from PySide6.QtCore import QAbstractItemModel, QMargins, QModelIndex, QRectF, QSize, Qt
from PySide6.QtGui import QBrush, QColor, QTextDocument
from PySide6.QtGui import QBrush, QColor, QPalette, QPen, QTextCharFormat, QTextCursor, QTextDocument
from PySide6.QtWidgets import QDialog, QLineEdit, QListView, QStyle, QStyledItemDelegate, QVBoxLayout
from thefuzz import process

Expand Down Expand Up @@ -170,6 +170,7 @@ def _get_text_document(index):

def paint(self, painter, option, index) -> None:
if index.column() == 0:
painter.save()
if option.state & QStyle.StateFlag.State_Selected:
b = QBrush(option.palette.highlight())
painter.fillRect(option.rect, b)
Expand All @@ -182,13 +183,14 @@ def paint(self, painter, option, index) -> None:

annotation_text = model.get_annotation_for_item(item)
if annotation_text:
if option.state & QStyle.StateFlag.State_Selected:
painter.setPen(QPen(option.palette.color(QPalette.ColorRole.HighlightedText)))
painter.drawText(
option.rect.marginsRemoved(QMargins(3, 3, 3, 3)),
Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter,
annotation_text,
)

painter.save()
painter.translate(option.rect.topLeft())

if self._display_icons:
Expand All @@ -201,6 +203,13 @@ def paint(self, painter, option, index) -> None:
painter.drawText(icon_rect, Qt.AlignmentFlag.AlignCenter, icon_text)
painter.translate(self.icon_width, 0)

if option.state & QStyle.StateFlag.State_Selected:
cursor = QTextCursor(td)
cursor.select(QTextCursor.Document)
char_format = QTextCharFormat()
char_format.setForeground(option.palette.highlightedText())
cursor.mergeCharFormat(char_format)

td.drawContents(painter)
painter.restore()
else:
Expand Down

0 comments on commit bc30d22

Please sign in to comment.