Ejemplo n.º 1
0
    def paint(self, painter, option, index):
        painter.save()
        item = index.model().data(index, role=Qt.UserRole)

        self.reader.setFileName(item)
        image = QPixmap.fromImageReader(self.reader)
        painter.translate(option.rect.x(), option.rect.y())

        if option.state & (QStyle.State_Selected | QStyle.State_MouseOver):
            painter.setOpacity(1)
        else:
            painter.setOpacity(0.90)

        painter.drawPixmap(0, 0, image)
        painter.restore()
Ejemplo n.º 2
0
    def paintEvent(self, event):
        # Set checked depending on state
        self.image.setFileName(ThemeManager.CHECKED_PATH if self.
                               enabled else ThemeManager.UNCHECKED_PATH)

        # Init painter and draw image at correct location
        painter = QPainter(self)
        pixmap = QPixmap.fromImageReader(self.image)
        painter.setRenderHint(QPainter.HighQualityAntialiasing, True)
        painter.drawPixmap(0, (self.height() - pixmap.height()) / 2, pixmap)

        # Style font and draw text at correct location
        painter.setFont(self.font)
        pen = QPen()
        pen.setColor(ThemeManager.LABEL_QC if any([self.hovered, self.enabled])
                     else ThemeManager.LABEL_LOW_OPACITY_QC)
        painter.setPen(pen)
        painter.drawText(pixmap.width() + self.padding,
                         self.height() / 2 + self.nameHeight / 4, self.name)