Exemplo n.º 1
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, empty_index)
     theme = index.data(Qt.UserRole)
     if not theme:
         return
     painter.save()
     pixmap = index.data(Qt.DecorationRole)
     if pixmap and not pixmap.isNull():
         rect = option.rect.adjusted(0, self.SPACING,
                                     COVER_SIZE[0] - option.rect.width(),
                                     -self.SPACING)
         painter.drawPixmap(rect, pixmap)
     if option.state & QStyle.State_Selected:
         painter.setPen(
             QPen(QApplication.instance().palette().highlightedText().color(
             )))
     bottom = option.rect.bottom() - 2
     painter.drawLine(0, bottom, option.rect.right(), bottom)
     if 'static-text' not in theme:
         theme['static-text'] = QStaticText(
             _('''
         <h1>{title}</h1>
         <p>by <i>{author}</i> with <b>{number}</b> icons [{size}]</p>
         <p>{description}</p>
         <p>Version: {version} Number of users: {usage}</p>
         '''.format(
                 title=theme.get('title', _('Unknown')),
                 author=theme.get('author', _('Unknown')),
                 number=theme.get('number', 0),
                 description=theme.get('description', ''),
                 size=human_readable(theme.get('compressed-size', 0)),
                 version=theme.get('version', 1),
                 usage=theme.get('usage', 0),
             )))
     painter.drawStaticText(COVER_SIZE[0] + self.SPACING,
                            option.rect.top() + self.SPACING,
                            theme['static-text'])
     painter.restore()
Exemplo n.º 2
0
 def paintEvent(self, ev):
     painter = QPainter(self)
     painter.setClipRect(ev.rect())
     pal = self.palette()
     painter.fillRect(self.rect(), pal.color(QPalette.ColorRole.Text))
     crect = self.rect().adjusted(1, 1, -1, -1)
     painter.fillRect(crect, pal.color(QPalette.ColorRole.Base))
     painter.setClipRect(crect)
     painter.setFont(self.parent().font())
     width = self.rect().width()
     for i, st, y, height in self.iter_visible_items():
         painter.save()
         if i == self.current_index:
             painter.fillRect(1, y, width, height, pal.color(pal.Highlight))
             color = pal.color(QPalette.ColorRole.HighlightedText).name()
             st = QStaticText(st)
             text = st.text().partition('>')[2]
             st.setText('<span style="color: %s">%s' % (color, text))
         painter.drawStaticText(self.SIDE_MARGIN, y, st)
         painter.restore()
     painter.end()
     if self.current_size_hint is None:
         QTimer.singleShot(0, self.layout)
Exemplo n.º 3
0
 def make_text(self, text, positions):
     text = QStaticText(make_highlighted_text(self.EMPH, text, positions))
     text.setTextOption(self.text_option)
     text.setTextFormat(Qt.RichText)
     return text
Exemplo n.º 4
0
 def make_text(self, text, positions):
     text = QStaticText(
         make_highlighted_text(emphasis_style(), text, positions))
     text.setTextOption(self.text_option)
     text.setTextFormat(Qt.TextFormat.RichText)
     return text