Skip to content

Commit

Permalink
Merge pull request #6011 from ales-erjavec/data-table-text-color
Browse files Browse the repository at this point in the history
[FIX] TableModel: Define foreground color when providing background
  • Loading branch information
PrimozGodec authored Jun 10, 2022
2 parents 88a8104 + 26cae39 commit 0879bee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Orange/widgets/utils/itemdelegates.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,7 @@ class TableDataDelegate(DataDelegate):
:class:`Orange.widgets.utils.itemmodels.TableModel`
"""
#: Roles supplied by TableModel we want DataDelegate to use.
DefaultRoles = (Qt.DisplayRole, Qt.TextAlignmentRole, Qt.BackgroundRole)
DefaultRoles = (
Qt.DisplayRole, Qt.TextAlignmentRole, Qt.BackgroundRole,
Qt.ForegroundRole
)
8 changes: 8 additions & 0 deletions Orange/widgets/utils/itemmodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,7 @@ def data(self, index, role,
_Qt_DisplayRole=Qt.DisplayRole,
_Qt_EditRole=Qt.EditRole,
_Qt_BackgroundRole=Qt.BackgroundRole,
_Qt_ForegroundRole=Qt.ForegroundRole,
_ValueRole=ValueRole,
_ClassValueRole=ClassValueRole,
_VariableRole=VariableRole,
Expand All @@ -956,6 +957,7 @@ def data(self, index, role,
_recognizedRoles=frozenset([Qt.DisplayRole,
Qt.EditRole,
Qt.BackgroundRole,
Qt.ForegroundRole,
ValueRole,
ClassValueRole,
VariableRole,
Expand Down Expand Up @@ -990,6 +992,12 @@ def data(self, index, role,
return instance[coldesc.var]
elif role == _Qt_BackgroundRole:
return coldesc.background
elif role == _Qt_ForegroundRole:
if coldesc.background is not None:
# The background is light-ish, force dark text color
return QColor(0, 0, 0, 200)
else:
return None
elif role == _ValueRole and isinstance(coldesc, TableModel.Column):
return instance[coldesc.var]
elif role == _ClassValueRole:
Expand Down

0 comments on commit 0879bee

Please sign in to comment.