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

[FIX] TableModel: Define foreground color when providing background #6011

Merged
merged 1 commit into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
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
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