Esempio n. 1
0
 def initStyleOption(self, option, index):
     """
     Initialize `option` with the values using the `index` index. When the
     item (0,1) is processed, it is styled especially. All other items are
     passed to the original `initStyleOption()` which then calls `displayText()`.
     Afterwards, check whether an fixpoint overflow has occured and color item
     background accordingly.
     """
     if index.row() == 0 and index.column() == 1: # a[0]: always 1
         option.text = "1" # QString object
         option.font.setBold(True)
         option.displayAlignment = Qt.AlignRight | Qt.AlignCenter
         # see http://zetcode.com/gui/pyqt5/painting/ :
         option.backgroundBrush = QBrush(Qt.BDiagPattern)#QColor(100, 200, 100, 200))
         option.backgroundBrush.setColor(QColor(100, 100, 100, 200))
         # don't continue with default initStyleOption... display routine ends here
     else:
         # continue with the original `initStyleOption()` and call displayText()
         super(ItemDelegate, self).initStyleOption(option, index)
         # test whether fixpoint conversion during displayText() created an overflow:
         if self.parent.myQ.ovr_flag > 0:
             # Color item backgrounds with pos. Overflows red
             option.backgroundBrush = QBrush(Qt.SolidPattern)
             option.backgroundBrush.setColor(QColor(100, 0, 0, 80))
         elif self.parent.myQ.ovr_flag < 0:
             # Color item backgrounds with neg. Overflows blue
             option.backgroundBrush = QBrush(Qt.SolidPattern)
             option.backgroundBrush.setColor(QColor(0, 0, 100, 80))
Esempio n. 2
0
    def initStyleOption(self, option, index):
        """
        Initialize `option` with the values using the `index` index. All items are
        passed to the original `initStyleOption()` which then calls `displayText()`.

        Afterwards, check whether a pole (index.column() == 1 )is outside the
        UC and color item background accordingly (not implemented yet).
        """
        # continue with the original `initStyleOption()` and call displayText()
        super(ItemDelegate, self).initStyleOption(option, index)
        # test whether fixpoint conversion during displayText() created an overflow:
        if index.column() == 1 and False:
            # Color item backgrounds with pos. Overflows red
            option.backgroundBrush = QBrush(Qt.SolidPattern)
            option.backgroundBrush.setColor(QColor(100, 0, 0, 80))