Skip to content

Commit

Permalink
owdistancematrix: Specify foreground when overriding background
Browse files Browse the repository at this point in the history
  • Loading branch information
ales-erjavec committed Nov 4, 2021
1 parent a738c00 commit f657bad
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Orange/widgets/unsupervised/owdistancematrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def dimension(self, parent=None):

def color_for_label(self, ind, light=100):
if self.label_colors is None:
return Qt.lightGray
return None
return QBrush(self.label_colors[ind].lighter(light))

def color_for_cell(self, row, col):
Expand All @@ -79,7 +79,7 @@ def data(self, index, role=Qt.DisplayRole):
return Qt.AlignRight | Qt.AlignVCenter
row, col = index.row(), index.column()
if self.distances is None:
return
return None
if role == TableBorderItem.BorderColorRole:
return self.color_for_label(col), self.color_for_label(row)
if role == FixedFormatNumericColumnDelegate.ColumnDataSpanRole:
Expand All @@ -92,15 +92,21 @@ def data(self, index, role=Qt.DisplayRole):
return float(self.distances[row, col])
if role == Qt.BackgroundColorRole:
return self.color_for_cell(row, col)
if role == Qt.ForegroundRole:
return QColor(Qt.black) # the background is light-ish
return None

def headerData(self, ind, orientation, role):
if not self.labels:
return
return None
if role == Qt.DisplayRole and ind < len(self.labels):
return self.labels[ind]
# On some systems, Qt doesn't respect the following role in the header
if role == Qt.BackgroundRole:
return self.color_for_label(ind, 150)
if role == Qt.ForegroundRole and self.label_colors is not None:
return QColor(Qt.black)
return None


class TableBorderItem(FixedFormatNumericColumnDelegate):
Expand Down Expand Up @@ -193,7 +199,9 @@ def __init__(self):
view.setWordWrap(False)
view.setTextElideMode(Qt.ElideNone)
view.setEditTriggers(QTableView.NoEditTriggers)
view.setItemDelegate(TableBorderItem(roles=(Qt.DisplayRole, Qt.BackgroundRole)))
view.setItemDelegate(
TableBorderItem(
roles=(Qt.DisplayRole, Qt.BackgroundRole, Qt.ForegroundRole)))
view.setModel(self.tablemodel)
view.setShowGrid(False)
for header in (view.horizontalHeader(), view.verticalHeader()):
Expand Down

0 comments on commit f657bad

Please sign in to comment.