I have a QTreeWidget that has values in them, which I only want to show a certain number of decimals but keep the precision for calculation purposes. I have it working correctly, but the highlighting of the selected items are messed up and show white around the cell that has been drawn.
How can I fix the highlighting so that is solid blue for the entire row?
class InitialDelegate(QtWidgets.QItemDelegate):
'Changes number of decimal places in gas analysis self.chosen table'
def __init__(self, decimals, parent=None):
super().__init__(parent)
self.nDecimals = decimals
def paint(self, painter, option, index):
if index.column() == 1:
value = index.model().data(index, QtCore.Qt.DisplayRole)
try:
number = float(value)
painter.drawText(option.rect, QtCore.Qt.AlignCenter , "{:.{}f}".format(number, self.nDecimals))
except:
QtWidgets.QItemDelegate.paint(self, painter, option, index)
else:
QtWidgets.QItemDelegate.paint(self, painter, option, index)
This is what it produces: