Skip to content

Commit 4035846

Browse files
committed
owdistancematrix: Specify foreground when overriding background
1 parent 5cd445a commit 4035846

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

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

7777
def color_for_cell(self, row, col):
@@ -82,7 +82,7 @@ def data(self, index, role=Qt.DisplayRole):
8282
return Qt.AlignRight | Qt.AlignVCenter
8383
row, col = index.row(), index.column()
8484
if self.distances is None:
85-
return
85+
return None
8686
if role == TableBorderItem.BorderColorRole:
8787
return self.color_for_label(col), self.color_for_label(row)
8888
if role == FixedFormatNumericColumnDelegate.ColumnDataSpanRole:
@@ -95,15 +95,21 @@ def data(self, index, role=Qt.DisplayRole):
9595
return float(self.distances[row, col])
9696
if role == Qt.BackgroundColorRole:
9797
return self.color_for_cell(row, col)
98+
if role == Qt.ForegroundRole:
99+
return QColor(Qt.black) # the background is light-ish
100+
return None
98101

99102
def headerData(self, ind, orientation, role):
100103
if not self.labels:
101-
return
104+
return None
102105
if role == Qt.DisplayRole and ind < len(self.labels):
103106
return self.labels[ind]
104107
# On some systems, Qt doesn't respect the following role in the header
105108
if role == Qt.BackgroundRole:
106109
return self.color_for_label(ind, 150)
110+
if role == Qt.ForegroundRole and self.label_colors is not None:
111+
return QColor(Qt.black)
112+
return None
107113

108114

109115
class TableBorderItem(FixedFormatNumericColumnDelegate):
@@ -196,7 +202,9 @@ def __init__(self):
196202
view.setWordWrap(False)
197203
view.setTextElideMode(Qt.ElideNone)
198204
view.setEditTriggers(QTableView.NoEditTriggers)
199-
view.setItemDelegate(TableBorderItem(roles=(Qt.DisplayRole, Qt.BackgroundRole)))
205+
view.setItemDelegate(
206+
TableBorderItem(
207+
roles=(Qt.DisplayRole, Qt.BackgroundRole, Qt.ForegroundRole)))
200208
view.setModel(self.tablemodel)
201209
view.setShowGrid(False)
202210
for header in (view.horizontalHeader(), view.verticalHeader()):

0 commit comments

Comments
 (0)