Formatters - labsquare/cutevariant GitHub Wiki

Formatters allow you to customize the display of variants. For example, using a QPainter you can change the color of a cell according to its value. This feature works as plugins does. Just create a file with Formatter subclass definition and put it inside the <cutevariant_rootFolder>/cutevariant/gui/formatters/ directory.

Code example

The following example illustrates how to display impact field as red if its value is 'HIGH'

from cutevariant.gui.formatter import Formatter
class SeqoneFormatter(Formatter):

    DISPLAY_NAME = "MyFormatter"
    def __init__(self):
        super().__init__()

    def paint(self, painter, option, index):
        # Get field name from index (QModelIndex)
        field_name = self.field_name(index).lower()
        # Get field value from index
        value = self.value(index)
        # Draw red text if condition as valid
        if field_name == 'impact' and value == 'HIGH':
            painter.setPen(QPen(QColor("red")))
            painter.drawText(option.rect, Qt.AlignCenter, value)
            return 
        # Otherwise, the default style is used