Skip to content

Commit 55ff045

Browse files
committed
owdistancematrix: Specify foreground when overriding background
1 parent d19cb06 commit 55ff045

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
@@ -69,7 +69,7 @@ def dimension(self, parent=None):
6969

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

7575
def color_for_cell(self, row, col):
@@ -80,7 +80,7 @@ def data(self, index, role=Qt.DisplayRole):
8080
return Qt.AlignRight | Qt.AlignVCenter
8181
row, col = index.row(), index.column()
8282
if self.distances is None:
83-
return
83+
return None
8484
if role == TableBorderItem.BorderColorRole:
8585
return self.color_for_label(col), self.color_for_label(row)
8686
if role == FixedFormatNumericColumnDelegate.ColumnDataSpanRole:
@@ -93,15 +93,21 @@ def data(self, index, role=Qt.DisplayRole):
9393
return float(self.distances[row, col])
9494
if role == Qt.BackgroundColorRole:
9595
return self.color_for_cell(row, col)
96+
if role == Qt.ForegroundRole:
97+
return QColor(Qt.black) # the background is light-ish
98+
return None
9699

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

106112

107113
class TableBorderItem(FixedFormatNumericColumnDelegate):
@@ -194,7 +200,9 @@ def __init__(self):
194200
view.setWordWrap(False)
195201
view.setTextElideMode(Qt.ElideNone)
196202
view.setEditTriggers(QTableView.NoEditTriggers)
197-
view.setItemDelegate(TableBorderItem(roles=(Qt.DisplayRole, Qt.BackgroundRole)))
203+
view.setItemDelegate(
204+
TableBorderItem(
205+
roles=(Qt.DisplayRole, Qt.BackgroundRole, Qt.ForegroundRole)))
198206
view.setModel(self.tablemodel)
199207
view.setShowGrid(False)
200208
for header in (view.horizontalHeader(), view.verticalHeader()):

0 commit comments

Comments
 (0)