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


Python QTextCharFormat.setFontWeight方法代码示例

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


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

示例1: initializeFormats

# 需要导入模块: from PyQt5.Qt import QTextCharFormat [as 别名]
# 或者: from PyQt5.Qt.QTextCharFormat import setFontWeight [as 别名]
    def initializeFormats(self):
        Config = self.Config
        Config["fontfamily"] = "monospace"
        for name, color, bold, italic in (
                ("normal", "#000000", False, False),
                ("keyword", "#000080", True, False),
                ("builtin", "#0000A0", False, False),
                ("comment", "#007F00", False, True),
                ("string", "#808000", False, False),
                ("number", "#924900", False, False),
                ("lparen", "#000000", True, True),
                ("rparen", "#000000", True, True)):
            Config["%sfontcolor" % name] = color
            Config["%sfontbold" % name] = bold
            Config["%sfontitalic" % name] = italic
        baseFormat = QTextCharFormat()
        baseFormat.setFontFamily(Config["fontfamily"])
        Config["fontsize"] = gprefs['gpm_template_editor_font_size']
        baseFormat.setFontPointSize(Config["fontsize"])

        for name in ("normal", "keyword", "builtin", "comment",
                     "string", "number", "lparen", "rparen"):
            format = QTextCharFormat(baseFormat)
            format.setForeground(QColor(Config["%sfontcolor" % name]))
            if Config["%sfontbold" % name]:
                format.setFontWeight(QFont.Bold)
            format.setFontItalic(Config["%sfontitalic" % name])
            self.Formats[name] = format
开发者ID:AEliu,项目名称:calibre,代码行数:30,代码来源:template_dialog.py

示例2: parse_text_formatting

# 需要导入模块: from PyQt5.Qt import QTextCharFormat [as 别名]
# 或者: from PyQt5.Qt.QTextCharFormat import setFontWeight [as 别名]
def parse_text_formatting(text):
    pos = 0
    tokens = []
    for m in re.finditer(r'</?([a-zA-Z1-6]+)/?>', text):
        q = text[pos:m.start()]
        if q:
            tokens.append((False, q))
        tokens.append((True, (m.group(1).lower(), '/' in m.group()[:2])))
        pos = m.end()
    if tokens:
        if text[pos:]:
            tokens.append((False, text[pos:]))
    else:
        tokens = [(False, text)]

    ranges, open_ranges, text = [], [], []
    offset = 0
    for is_tag, tok in tokens:
        if is_tag:
            tag, closing = tok
            if closing:
                if open_ranges:
                    r = open_ranges.pop()
                    r[-1] = offset - r[-2]
                    if r[-1] > 0:
                        ranges.append(r)
            else:
                if tag in {'b', 'strong', 'i', 'em'}:
                    open_ranges.append([tag, offset, -1])
        else:
            offset += len(tok.replace('&amp;', '&'))
            text.append(tok)
    text = ''.join(text)
    formats = []
    for tag, start, length in chain(ranges, open_ranges):
        fmt = QTextCharFormat()
        if tag in {'b', 'strong'}:
            fmt.setFontWeight(QFont.Bold)
        elif tag in {'i', 'em'}:
            fmt.setFontItalic(True)
        else:
            continue
        if length == -1:
            length = len(text) - start
        if length > 0:
            r = QTextLayout.FormatRange()
            r.format = fmt
            r.start, r.length = start, length
            formats.append(r)
    return text, formats
开发者ID:artbycrunk,项目名称:calibre,代码行数:52,代码来源:covers.py

示例3: __init__

# 需要导入模块: from PyQt5.Qt import QTextCharFormat [as 别名]
# 或者: from PyQt5.Qt.QTextCharFormat import setFontWeight [as 别名]
 def __init__( self, pattern, color,
               weight=QFont.Normal,
               style=Qt.SolidPattern,
               blocknum=0):
     if isinstance(pattern,basestring):
         self.pattern = re.compile(pattern)
     else:
         self.pattern=pattern
     charfmt = QTextCharFormat()
     brush = QBrush(color, style)
     charfmt.setForeground(brush)
     charfmt.setFontWeight(weight)
     self.highlight = charfmt
     self.blocknum=blocknum
开发者ID:iceshipping,项目名称:FanFicFare,代码行数:16,代码来源:inihighlighter.py

示例4: __init__

# 需要导入模块: from PyQt5.Qt import QTextCharFormat [as 别名]
# 或者: from PyQt5.Qt.QTextCharFormat import setFontWeight [as 别名]
    def __init__(self, controller):
        super().__init__()
        formc = QTextCharFormat()
        formc.setFontItalic(True)
        formc.setFontWeight(3)
        form = QTextBlockFormat()
        form.setLineHeight(200, 1)


        cur = self.textCursor()
        cur.insertText('', self.format_p)
        new_speech_signal = QObject()
        controller.speech.connect(self.new_speech_signal.emit)
        controller.speech.start()
        self.new_speech_signal.connect(cur.insertText)
开发者ID:aaronschif,项目名称:sp,代码行数:17,代码来源:__main__.py

示例5: initializeFormats

# 需要导入模块: from PyQt5.Qt import QTextCharFormat [as 别名]
# 或者: from PyQt5.Qt.QTextCharFormat import setFontWeight [as 别名]
    def initializeFormats(cls):
        if cls.Formats:
            return
        baseFormat = QTextCharFormat()
        baseFormat.setFontFamily('monospace')
        baseFormat.setFontPointSize(11)
        for name, color, bold, italic in (
                ("normal", "#000000", False, False),
                ("keyword", "#000080", True, False),
                ("builtin", "#0000A0", False, False),
                ("constant", "#0000C0", False, False),
                ("decorator", "#0000E0", False, False),
                ("comment", "#007F00", False, True),
                ("string", "#808000", False, False),
                ("number", "#924900", False, False),
                ("error", "#FF0000", False, False),
                ("pyqt", "#50621A", False, False)):

            format = QTextCharFormat(baseFormat)
            format.setForeground(QColor(color))
            if bold:
                format.setFontWeight(QFont.Bold)
            format.setFontItalic(italic)
            cls.Formats[name] = format
开发者ID:JimmXinu,项目名称:calibre,代码行数:26,代码来源:widgets.py


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