当前位置: 首页>>代码示例>>Python>>正文


Python Qt.QStaticText类代码示例

本文整理汇总了Python中PyQt5.Qt.QStaticText的典型用法代码示例。如果您正苦于以下问题:Python QStaticText类的具体用法?Python QStaticText怎么用?Python QStaticText使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QStaticText类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: paint

 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, index)
     pal = option.palette
     color = pal.color(pal.HighlightedText if option.state & QStyle.State_Selected else pal.Text).name()
     text = '<div style="color:%s">%s</div>' % (color, index.data(RENDER_ROLE))
     st = QStaticText(text)
     st.setTextWidth(option.rect.width())
     painter.drawStaticText(option.rect.left() + self.MARGIN // 2, option.rect.top() + self.MARGIN // 2, st)
开发者ID:JapaChin,项目名称:calibre,代码行数:8,代码来源:tag_mapper.py

示例2: sizeHint

 def sizeHint(self, option, index):
     st = QStaticText(index.data(RENDER_ROLE))
     st.prepare(font=self.parent().font())
     width = max(option.rect.width(), self.parent().width() - 50)
     if width and width != st.textWidth():
         st.setTextWidth(width)
     br = st.size()
     return QSize(br.width(), br.height() + self.MARGIN)
开发者ID:JapaChin,项目名称:calibre,代码行数:8,代码来源:tag_mapper.py

示例3: set_message

 def set_message(self, text, color_, bold=False, is_permanent=False):
     from vise.view import certificate_error_domains
     key = (text, color_.name(), bold, is_permanent)
     if key == self.current_key:
         return
     self.current_key = key
     self.is_permanent = is_permanent
     prefix = text.partition(':')[0]
     self.is_address = self.is_permanent and prefix.lower() in {'http', 'https', 'vise'}
     self.is_secure = prefix.lower() in {'https', 'vise'}
     color_ = color_ or self.palette().color(self.palette().WindowText)
     if self.is_address:
         qurl = QUrl(text)
         if self.is_secure and qurl.host() in certificate_error_domains:
             self.is_secure = False
         if qurl.scheme() == 'vise':
             host = qurl.path()
             rest = ''
             sep = ':'
         else:
             host = qurl.host()
             rest = qurl.toDisplayString(QUrl.PrettyDecoded | QUrl.RemoveScheme | QUrl.RemoveAuthority)
             sep = '://'
         self.static_text = QStaticText(
             '<span style="white-space:nowrap; color: {fg}">'
             '<span style="color:{emph}; font-weight:bold">{scheme}</span><span style="color:{dull}">{sep}</span>'
             '<span style="color:{fg}">{host}</span>'
             '<span style="color:{dull}">{rest}</span>'.format(
                 fg=color_.name(), emph='green' if self.is_secure else 'red', scheme=escape(qurl.scheme()),
                 host=escape(host), dull=color('status bar dull foreground', 'gray'), sep=sep,
                 rest=escape(rest)
             ))
     else:
         self.static_text = QStaticText('<span style="color:{}; font-weight: {}; white-space:nowrap">{}</span>'.format(
             color_.name(), ('bold' if bold else 'normal'), escape(text)))
     to = QTextOption(Qt.AlignLeft | Qt.AlignTop)
     to.setWrapMode(to.NoWrap)
     self.static_text.setTextOption(to)
     self.static_text.prepare(font=self.font())
     self.update()
开发者ID:kovidgoyal,项目名称:vise,代码行数:40,代码来源:status_bar.py

示例4: paintEvent

 def paintEvent(self, ev):
     painter = QPainter(self)
     painter.setClipRect(ev.rect())
     pal = self.palette()
     painter.fillRect(self.rect(), pal.color(pal.Text))
     crect = self.rect().adjusted(1, 1, -1, -1)
     painter.fillRect(crect, pal.color(pal.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.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)
开发者ID:JimmXinu,项目名称:calibre,代码行数:23,代码来源:popup.py

示例5: make_highlighted_text

def make_highlighted_text(text, positions, emph='color:magenta', wrapper=None):
    positions = sorted(set(positions) - {-1})
    if positions:
        parts = []
        pos = 0
        for p in positions:
            ch = text[p]
            parts.append(escape(text[pos:p]))
            parts.append('<span style="%s">%s</span>' % (emph, escape(ch)))
            pos = p + len(ch)
        parts.append(escape(text[pos:]))
        text = ''.join(parts)
    if wrapper:
        text = '<span style="%s">%s</span>' % (wrapper, text)
    ans = QStaticText(text)
    to = ans.textOption()
    to.setWrapMode(to.NoWrap)
    ans.setTextOption(to)
    ans.setTextFormat(Qt.RichText)
    return ans
开发者ID:kovidgoyal,项目名称:vise,代码行数:20,代码来源:utils.py

示例6: Message

class Message(QWidget):

    def __init__(self, parent, sb_background):
        QWidget.__init__(self, parent)
        self.is_permanent = False
        self.is_address = False
        self.is_secure = False
        self.static_text = None
        self.current_key = None
        self.setFocusPolicy(Qt.NoFocus)
        self.sb_background = QColor(color(sb_background, self.palette().color(QPalette.Window)))

    def set_message(self, text, color_, bold=False, is_permanent=False):
        from vise.view import certificate_error_domains
        key = (text, color_.name(), bold, is_permanent)
        if key == self.current_key:
            return
        self.current_key = key
        self.is_permanent = is_permanent
        prefix = text.partition(':')[0]
        self.is_address = self.is_permanent and prefix.lower() in {'http', 'https', 'vise'}
        self.is_secure = prefix.lower() in {'https', 'vise'}
        color_ = color_ or self.palette().color(self.palette().WindowText)
        if self.is_address:
            qurl = QUrl(text)
            if self.is_secure and qurl.host() in certificate_error_domains:
                self.is_secure = False
            if qurl.scheme() == 'vise':
                host = qurl.path()
                rest = ''
                sep = ':'
            else:
                host = qurl.host()
                rest = qurl.toDisplayString(QUrl.PrettyDecoded | QUrl.RemoveScheme | QUrl.RemoveAuthority)
                sep = '://'
            self.static_text = QStaticText(
                '<span style="white-space:nowrap; color: {fg}">'
                '<span style="color:{emph}; font-weight:bold">{scheme}</span><span style="color:{dull}">{sep}</span>'
                '<span style="color:{fg}">{host}</span>'
                '<span style="color:{dull}">{rest}</span>'.format(
                    fg=color_.name(), emph='green' if self.is_secure else 'red', scheme=escape(qurl.scheme()),
                    host=escape(host), dull=color('status bar dull foreground', 'gray'), sep=sep,
                    rest=escape(rest)
                ))
        else:
            self.static_text = QStaticText('<span style="color:{}; font-weight: {}; white-space:nowrap">{}</span>'.format(
                color_.name(), ('bold' if bold else 'normal'), escape(text)))
        to = QTextOption(Qt.AlignLeft | Qt.AlignTop)
        to.setWrapMode(to.NoWrap)
        self.static_text.setTextOption(to)
        self.static_text.prepare(font=self.font())
        self.update()

    def paintEvent(self, ev):
        if not self.static_text or not self.static_text.text():
            return
        p = QPainter(self)
        p.setRenderHint(p.TextAntialiasing)
        # If text is too long too fit, fade it out at the end
        self.static_text.setTextWidth(self.rect().width())
        sz = self.static_text.size()
        r = self.rect()
        p.drawStaticText(0, (r.height() - sz.height()) // 2, self.static_text)
        if sz.width() > r.width():
            g = QLinearGradient(self.rect().topLeft(), self.rect().topRight())
            c = QColor(self.sb_background)
            c.setAlpha(0)
            g.setColorAt(0, c)
            g.setColorAt(0.8, c)
            g.setColorAt(1.0, self.sb_background)
            p.fillRect(self.rect(), QBrush(g))
        p.end()
开发者ID:kovidgoyal,项目名称:vise,代码行数:72,代码来源:status_bar.py


注:本文中的PyQt5.Qt.QStaticText类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。