Skip to content

Commit f657bad

Browse files
committed
owdistancematrix: Specify foreground when overriding background
1 parent a738c00 commit f657bad

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Orange/widgets/unsupervised/owdistancematrix.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def dimension(self, parent=None):
6868

6969
def color_for_label(self, ind, light=100):
7070
if self.label_colors is None:
71-
return Qt.lightGray
71+
return None
7272
return QBrush(self.label_colors[ind].lighter(light))
7373

7474
def color_for_cell(self, row, col):
@@ -79,7 +79,7 @@ def data(self, index, role=Qt.DisplayRole):
7979
return Qt.AlignRight | Qt.AlignVCenter
8080
row, col = index.row(), index.column()
8181
if self.distances is None:
82-
return
82+
return None
8383
if role == TableBorderItem.BorderColorRole:
8484
return self.color_for_label(col), self.color_for_label(row)
8585
if role == FixedFormatNumericColumnDelegate.ColumnDataSpanRole:
@@ -92,15 +92,21 @@ def data(self, index, role=Qt.DisplayRole):
9292
return float(self.distances[row, col])
9393
if role == Qt.BackgroundColorRole:
9494
return self.color_for_cell(row, col)
95+
if role == Qt.ForegroundRole:
96+
return QColor(Qt.black) # the background is light-ish
97+
return None
9598

9699
def headerData(self, ind, orientation, role):
97100
if not self.labels:
98-
return
101+
return None
99102
if role == Qt.DisplayRole and ind < len(self.labels):
100103
return self.labels[ind]
101104
# On some systems, Qt doesn't respect the following role in the header
102105
if role == Qt.BackgroundRole:
103106
return self.color_for_label(ind, 150)
107+
if role == Qt.ForegroundRole and self.label_colors is not None:
108+
return QColor(Qt.black)
109+
return None
104110

105111

106112
class TableBorderItem(FixedFormatNumericColumnDelegate):
@@ -193,7 +199,9 @@ def __init__(self):
193199
view.setWordWrap(False)
194200
view.setTextElideMode(Qt.ElideNone)
195201
view.setEditTriggers(QTableView.NoEditTriggers)
196-
view.setItemDelegate(TableBorderItem(roles=(Qt.DisplayRole, Qt.BackgroundRole)))
202+
view.setItemDelegate(
203+
TableBorderItem(
204+
roles=(Qt.DisplayRole, Qt.BackgroundRole, Qt.ForegroundRole)))
197205
view.setModel(self.tablemodel)
198206
view.setShowGrid(False)
199207
for header in (view.horizontalHeader(), view.verticalHeader()):

0 commit comments

Comments
 (0)