def data(self, index, role=Qt.DisplayRole):
"""Cell content"""
if not index.isValid():
return to_qvariant()
# if role == Qt.DecorationRole:
# return ima.icon('editcopy')
# if role == Qt.DisplayRole:
# return ""
if role == Qt.TextAlignmentRole:
return to_qvariant(int(Qt.AlignRight | Qt.AlignVCenter))
elif role == Qt.FontRole:
return self.font
value = self.get_value(index)
if role == Qt.DisplayRole:
if value is np.ma.masked:
return ''
# for headers
elif isinstance(value, str) and not isinstance(value, np.str_):
return value
else:
return to_qvariant(self._format % value)
elif role == Qt.BackgroundColorRole:
if self.bgcolor_possible and self.bg_gradient is not None and value is not np.ma.masked:
if self.bg_value is None:
try:
v = self.color_func(value) if self.color_func is not None else value
if -np.inf < v < self.vmin:
# TODO: this is suboptimal, as it can reset many times (though in practice, it is usually
# ok). When we get buffering, we will need to compute vmin/vmax on the whole buffer
# at once, eliminating this problem (and we could even compute final colors directly
# all at once)
self.vmin = v
self.reset()
elif self.vmax < v < np.inf:
self.vmax = v
self.reset()
v = scale_to_01range(v, self.vmin, self.vmax)
except TypeError:
v = np.nan
else:
i, j = index.row(), index.column()
v = self.bg_value[i, j]
return self.bg_gradient[v]
# elif role == Qt.ToolTipRole:
# return to_qvariant("{}\n{}".format(repr(value),self.get_labels(index)))
return to_qvariant()
评论列表
文章目录