Ejemplo n.º 1
0
    def sumOfColumn(self, column_idx: int):
        """

        :param column_idx:
        :return:
        """
        row_items = self._all_rows()

        column_sum = 0.0

        for item in row_items:
            column_value = self.itemAt(item.row(), column_idx)
            if column_value and Utils.isANumber(column_value):
                column_sum += float(column_value)

        return round(column_sum, 2)
Ejemplo n.º 2
0
    def set_column_background_color(self, color: QColor,
                                    base_column_index: int,
                                    colored_column: int):
        """

        :param color:
        :param base_column_index:
        :param colored_column:
        :return:
        """
        model = self.model()
        for row in range(model.rowCount()):
            if model.index(row, base_column_index).data():
                data = model.index(row, base_column_index).data()
                if Utils.isANumber(data):
                    if float(data) < 0:
                        color = QColor('#BFEFFF')

                    model.item(row, colored_column).setBackground(color)
Ejemplo n.º 3
0
 def set_column_foreground_color(self, base_column_index: int,
                                 colored_column: int):
     """
     Set the color of the column whose contents are numbers.
     :param base_column_index:
     :param colored_column:
     :return:
     """
     model = self.model()
     for row in range(model.rowCount()):
         if model.index(row, base_column_index).data():
             data = model.index(row, base_column_index).data()
             if Utils.isANumber(data):
                 if float(data) < 0:
                     color = QColor('green')
                 elif float(data) == 0.00:
                     color = QColor('black')
                 else:
                     color = QColor('red')
                 model.item(row, colored_column).setForeground(color)