示例#1
0
 def paint(self, painter, option, index):
     value = index.data(Qt.DisplayRole)
     style = QApplication.style()
     opt = QStyleOptionComboBox()
     opt.text = str(value)
     opt.rect = option.rect
     style.drawComplexControl(QStyle.CC_ComboBox, opt, painter)
     QItemDelegate.paint(self, painter, option, index)
示例#2
0
 def paint(self, painter, option, index):
     if self._is_relationship_index(index):
         super().paint(painter, option, index)
     else:
         QItemDelegate.paint(self, painter, option, index)
示例#3
0
    def paint(self, painter: QPainter, option: QStyleOptionViewItem,
              index: QModelIndex):
        """
        Displays dirty files in red with corresponding rebuild buttons
        if in developer mode (is_dev_mode). Otherwise, renders normally


        Args:
            painter (QPainter): Current painter
            option (QStyleOptionViewItem): Current option
            index (QModelIndex): Current index of related model



        """
        if self.is_dev_mode:
            source_model = self.get_source_model(index.model(),
                                                 self.source_model_type)

            model = index.model()

            # get data of filename
            filename = str(
                model.data(
                    model.sibling(index.row(), source_model.FILENAME, index)))

            if source_model.is_file_dirty(filename):
                if index.column() == source_model.FILENAME:

                    text = filename
                    palette = option.palette
                    document = QTextDocument()
                    document.setDefaultFont(option.font)
                    document.setHtml(f"<font color={'red'}>{text}</font>")
                    background_color = palette.base().color()
                    painter.save()
                    painter.fillRect(option.rect, background_color)
                    painter.translate(option.rect.x(), option.rect.y())
                    document.drawContents(painter)
                    painter.restore()

                elif index.column() == source_model.REBUILD:
                    if '.py' in filename:
                        text = "rebuild"
                        palette = option.palette
                        document = QTextDocument()
                        # needed to add Right Alignment:  qt bug :
                        # https://bugreports.qt.io/browse/QTBUG-22851
                        document.setTextWidth(option.rect.width())
                        text_options = document.defaultTextOption()
                        text_options.setTextDirection(Qt.RightToLeft)
                        document.setDefaultTextOption(
                            text_options)  # get right alignment
                        document.setDefaultFont(option.font)
                        document.setHtml(
                            f'<font color={"red"}> <b> {text}</b> </font>')
                        background_color = palette.base().color()
                        painter.save()
                        painter.fillRect(option.rect, background_color)
                        painter.translate(option.rect.x(), option.rect.y())
                        document.drawContents(painter)
                        painter.restore()

            else:
                QItemDelegate.paint(self, painter, option, index)

        else:
            QItemDelegate.paint(self, painter, option, index)
示例#4
0
 def paint(self, painter, option, index):
     option.displayAlignment = QtCore.Qt.AlignCenter
     QItemDelegate.paint(self, painter, option, index)
 def paint(self, painter, option, index):
     if self._is_entity_index(index):
         super().paint(painter, option, index)
     else:
         QItemDelegate.paint(self, painter, option, index)