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


Python QTextCharFormat.setForeground方法代码示例

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


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

示例1: css2fmt

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setForeground [as 别名]
def css2fmt(d, f=None):
    """Convert a css dictionary to a QTextCharFormat."""
    if f is None:
        f = QTextCharFormat()
    v = d.get('font-style')
    if v:
        f.setFontItalic(v in ('oblique', 'italic'))
    v = d.get('font-weight')
    if v:
        if v == 'bold':
            f.setFontWeight(QFont.Bold)
        elif v == 'normal':
            f.setFontWeight(QFont.Normal)
        elif v.isdigit():
            f.setFontWeight(int(v) / 10)
    v = d.get('color')
    if v:
        f.setForeground(QColor(v))
    v = d.get('background')
    if v:
        f.setBackground(QColor(v))
    v = d.get('text-decoration')
    if v:
        f.setFontUnderline(v == 'underline')
    v = d.get('text-decoration-color')
    if v:
        f.setUnderlineColor(QColor(v))
    return f
开发者ID:AlexSchr,项目名称:frescobaldi,代码行数:30,代码来源:textformats.py

示例2: XmlSyntaxHighlighter

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setForeground [as 别名]
class XmlSyntaxHighlighter(QSyntaxHighlighter):

    def __init__(self, parent=None):
        super(XmlSyntaxHighlighter, self).__init__(parent)

        self.highlightingRules = []

        # Tag format.
        format = QTextCharFormat()
        format.setForeground(Qt.darkBlue)
        format.setFontWeight(QFont.Bold)
        pattern = QRegExp("(<[a-zA-Z:]+\\b|<\\?[a-zA-Z:]+\\b|\\?>|>|/>|</[a-zA-Z:]+>)")
        self.highlightingRules.append((pattern, format))

        # Attribute format.
        format = QTextCharFormat()
        format.setForeground(Qt.darkGreen)
        pattern = QRegExp("[a-zA-Z:]+=")
        self.highlightingRules.append((pattern, format))

        # Attribute content format.
        format = QTextCharFormat()
        format.setForeground(Qt.red)
        pattern = QRegExp("(\"[^\"]*\"|'[^']*')")
        self.highlightingRules.append((pattern, format))

        # Comment format.
        self.commentFormat = QTextCharFormat()
        self.commentFormat.setForeground(Qt.lightGray)
        self.commentFormat.setFontItalic(True)

        self.commentStartExpression = QRegExp("<!--")
        self.commentEndExpression = QRegExp("-->")

    def highlightBlock(self, text):
        for pattern, format in self.highlightingRules:
            expression = QRegExp(pattern)
            index = expression.indexIn(text)
            while index >= 0:
                length = expression.matchedLength()
                self.setFormat(index, length, format)
                index = expression.indexIn(text, index + length)

        self.setCurrentBlockState(0)

        startIndex = 0
        if self.previousBlockState() != 1:
            startIndex = self.commentStartExpression.indexIn(text)

        while startIndex >= 0:
            endIndex = self.commentEndExpression.indexIn(text, startIndex)
            if endIndex == -1:
                self.setCurrentBlockState(1)
                commentLength = text.length() - startIndex
            else:
                commentLength = endIndex - startIndex + self.commentEndExpression.matchedLength()

            self.setFormat(startIndex, commentLength, self.commentFormat)
            startIndex = self.commentStartExpression.indexIn(text,
                    startIndex + commentLength)
开发者ID:death-finger,项目名称:Scripts,代码行数:62,代码来源:schema.py

示例3: highlightBlock

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setForeground [as 别名]
	def highlightBlock(self, text):
		patterns = (
			# regex,         color,            font style,    italic, underline
			(reHtmlTags,     'htmlTags',       QFont.Bold),                     # 0
			(reHtmlSymbols,  'htmlSymbols',    QFont.Bold),                     # 1
			(reHtmlStrings,  'htmlStrings',    QFont.Bold),                     # 2
			(reHtmlComments, 'htmlComments',   QFont.Normal),                   # 3
			(reAsterisks,    None,             QFont.Normal,  True),            # 4
			(reUnderline,    None,             QFont.Normal,  True),            # 5
			(reDblAsterisks, None,             QFont.Bold),                     # 6
			(reDblUnderline, None,             QFont.Bold),                     # 7
			(reTrpAsterisks, None,             QFont.Bold,    True),            # 8
			(reTrpUnderline, None,             QFont.Bold,    True),            # 9
			(reMkdHeaders,   None,             QFont.Black),                    # 10
			(reMkdLinksImgs, 'markdownLinks',  QFont.Normal),                   # 11
			(reMkdLinkRefs,  None,             QFont.Normal,  True,   True),    # 12
			(reBlockQuotes,  'blockquotes',    QFont.Normal),                   # 13
			(reReSTDirects,  'restDirectives', QFont.Bold),                     # 14
			(reReSTRoles,    'restRoles',      QFont.Bold),                     # 15
			(reTextileHdrs,  None,             QFont.Black),                    # 16
			(reTextileQuot,  'blockquotes',    QFont.Normal),                   # 17
			(reAsterisks,    None,             QFont.Bold),                     # 18
			(reDblUnderline, None,             QFont.Normal,  True),            # 19
		)
		patternsDict = {
			'Markdown': (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13),
			'reStructuredText': (4, 6, 14, 15),
			'Textile': (0, 5, 6, 16, 17, 18, 19),
			'html': (0, 1, 2, 3)
		}
		# Syntax highlighter
		if self.docType in patternsDict:
			for number in patternsDict[self.docType]:
				pattern = patterns[number]
				charFormat = QTextCharFormat()
				charFormat.setFontWeight(pattern[2])
				if pattern[1] != None:
					charFormat.setForeground(colorScheme[pattern[1]])
				if len(pattern) >= 4:
					charFormat.setFontItalic(pattern[3])
				if len(pattern) >= 5:
					charFormat.setFontUnderline(pattern[4])
				for match in pattern[0].finditer(text):
					self.setFormat(match.start(), match.end() - match.start(), charFormat)
		for match in reSpacesOnEnd.finditer(text):
			charFormat = QTextCharFormat()
			charFormat.setBackground(colorScheme['whitespaceOnEnd'])
			self.setFormat(match.start(), match.end() - match.start(), charFormat)
		# Spell checker
		if self.dictionary:
			charFormat = QTextCharFormat()
			charFormat.setUnderlineColor(Qt.red)
			charFormat.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)
			for match in reWords.finditer(text):
				finalFormat = QTextCharFormat()
				finalFormat.merge(charFormat)
				finalFormat.merge(self.format(match.start()))
				if not self.dictionary.check(match.group(0)):
					self.setFormat(match.start(), match.end() - match.start(), finalFormat)
开发者ID:ahnan4arch,项目名称:retext,代码行数:61,代码来源:highlighter.py

示例4: __post_execution_message

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setForeground [as 别名]
 def __post_execution_message(self):
     """Print post execution message."""
     self.output.textCursor().insertText('\n\n')
     format_ = QTextCharFormat()
     format_.setAnchor(True)
     format_.setForeground(Qt.green)
     self.output.textCursor().insertText(
         _translate("RunWidget", "Post Execution Script Successfully executed."), format_)
开发者ID:Salmista-94,项目名称:Ninja_PyQt5,代码行数:10,代码来源:run_widget.py

示例5: textColor

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setForeground [as 别名]
    def textColor(self):
        col = QColorDialog.getColor(self.textEdit.textColor(), self)
        if not col.isValid():
            return

        fmt = QTextCharFormat()
        fmt.setForeground(col)
        self.mergeFormatOnWordOrSelection(fmt)
        self.colorChanged(col)
开发者ID:inzem77,项目名称:ws-chat2,代码行数:11,代码来源:textEdit.py

示例6: addTestResult

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setForeground [as 别名]
 def addTestResult(self, results):
     textCharFormat = QTextCharFormat()
     if results[0]:
         textCharFormat.setFontWeight(QFont.Bold)
     elif results[1] == False:
         textCharFormat.setForeground(Qt.yellow)
     self.plainTextEdit_methodResults.textCursor().insertText(results[2] + "\n", textCharFormat)
     self.plainTextEdit_methodResults.verticalScrollBar().setValue(
         self.plainTextEdit_methodResults.verticalScrollBar().maximum())
开发者ID:IlanHindy,项目名称:AI-Learn,代码行数:11,代码来源:MainWindow.py

示例7: weekendFormatChanged

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setForeground [as 别名]
    def weekendFormatChanged(self):
        format = QTextCharFormat()
        format.setForeground(
                Qt.GlobalColor(
                        self.weekendColorCombo.itemData(
                                self.weekendColorCombo.currentIndex())))

        self.calendar.setWeekdayTextFormat(Qt.Saturday, format)
        self.calendar.setWeekdayTextFormat(Qt.Sunday, format)
开发者ID:Axel-Erfurt,项目名称:pyqt5,代码行数:11,代码来源:calendarwidget.py

示例8: __init__

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setForeground [as 别名]
    def __init__(self):
        super(PugdebugFormatter, self).__init__()

        for token, style in self.style:
            format = QTextCharFormat()

            if style["color"]:
                color = QColor("#" + style["color"])
                format.setForeground(color)

            self.styles[str(token)] = format
开发者ID:mbarbon,项目名称:pugdebug,代码行数:13,代码来源:syntaxer.py

示例9: reformatHeaders

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setForeground [as 别名]
    def reformatHeaders(self):
        text = self.headerTextFormatCombo.currentText()
        format = QTextCharFormat()

        if text == "Bold":
            format.setFontWeight(QFont.Bold)
        elif text == "Italic":
            format.setFontItalic(True)
        elif text == "Green":
            format.setForeground(Qt.green)

        self.calendar.setHeaderTextFormat(format)
开发者ID:Axel-Erfurt,项目名称:pyqt5,代码行数:14,代码来源:calendarwidget.py

示例10: weekdayFormatChanged

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setForeground [as 别名]
    def weekdayFormatChanged(self):
        format = QTextCharFormat()
        format.setForeground(
                Qt.GlobalColor(
                        self.weekdayColorCombo.itemData(
                                self.weekdayColorCombo.currentIndex())))

        self.calendar.setWeekdayTextFormat(Qt.Monday, format)
        self.calendar.setWeekdayTextFormat(Qt.Tuesday, format)
        self.calendar.setWeekdayTextFormat(Qt.Wednesday, format)
        self.calendar.setWeekdayTextFormat(Qt.Thursday, format)
        self.calendar.setWeekdayTextFormat(Qt.Friday, format)
开发者ID:Axel-Erfurt,项目名称:pyqt5,代码行数:14,代码来源:calendarwidget.py

示例11: format

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setForeground [as 别名]
def format(color, style=''):

    word_color = QColor()
    word_color.setNamedColor(color)
    word_format = QTextCharFormat()
    word_format.setForeground(word_color)
    if 'italic' in style:
        word_format.setFontItalic(True)
    elif 'bold' in style:
        word_format.setFontWeight(QFont.Bold)

    return word_format
开发者ID:lfsando,项目名称:notepad,代码行数:14,代码来源:highlighter.py

示例12: highlightBlock

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setForeground [as 别名]
	def highlightBlock(self, text):
		patterns = (
			# regex,         color,          font style,    italic, underline
			(reHtmlTags,     colorScheme[0], QFont.Bold),
			(reHtmlSymbols,  colorScheme[1], QFont.Bold),
			(reHtmlStrings,  colorScheme[2], QFont.Bold),
			(reHtmlComments, colorScheme[3], QFont.Normal),
			(reItalics1,     None,           QFont.Normal,  True),
			(reItalics2,     None,           QFont.Normal,  True),
			(reBold1,        None,           QFont.Bold),
			(reBold2,        None,           QFont.Bold),
			(reBoldItalics1, None,           QFont.Bold,    True),
			(reBoldItalics2, None,           QFont.Bold,    True),
			(reMkdHeaders,   None,           QFont.Black),
			(reMkdLinksImgs, colorScheme[4], QFont.Normal),
			(reMkdLinkRefs,  None,           QFont.Normal,  True,   True),
			(reBlockQuotes,  colorScheme[5], QFont.Normal),
			(reReSTDirects,  colorScheme[6], QFont.Normal),
			(reReSTRoles,    colorScheme[7], QFont.Normal)
		)
		patternsDict = {
			DOCTYPE_NONE: (),
			DOCTYPE_MARKDOWN: (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13),
			DOCTYPE_REST: (4, 6, 14, 15),
			DOCTYPE_HTML: (0, 1, 2, 3)
		}
		# Syntax highlighter
		if self.docType in patternsDict:
			for number in patternsDict[self.docType]:
				pattern = patterns[number]
				charFormat = QTextCharFormat()
				charFormat.setFontWeight(pattern[2])
				if pattern[1] != None:
					charFormat.setForeground(pattern[1])
				if len(pattern) >= 4:
					charFormat.setFontItalic(pattern[3])
				if len(pattern) >= 5:
					charFormat.setFontUnderline(pattern[4])
				for match in pattern[0].finditer(text):
					self.setFormat(match.start(), match.end() - match.start(), charFormat)
		# Spell checker
		if self.dictionary:
			charFormat = QTextCharFormat()
			charFormat.setUnderlineColor(Qt.red)
			charFormat.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)
			for match in reWords.finditer(text):
				finalFormat = QTextCharFormat()
				finalFormat.merge(charFormat)
				finalFormat.merge(self.format(match.start()))
				if not self.dictionary.check(match.group(0)):
					self.setFormat(match.start(), match.end() - match.start(), finalFormat)
开发者ID:jmpews,项目名称:retext,代码行数:53,代码来源:highlighter.py

示例13: __init__

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setForeground [as 别名]
    def __init__(self, editor):
        super(Highlighter, self).__init__(editor)
        # Keywords format
        keyword_format = QTextCharFormat()
        keyword_format.setForeground(Qt.darkBlue)
        keyword_format.setFontWeight(QFont.Bold)

        # Rules
        self._rules = [(QRegExp("\\b" + pattern + "\\b"), keyword_format)
                       for pattern in Highlighter.KEYWORDS]

        # Number format
        number_format = QTextCharFormat()
        number_pattern = QRegExp(r"\b([A-Z0-9]+)(?:[ _-](\d+))?\b")
        number_pattern.setMinimal(True)
        number_format.setForeground(Qt.darkCyan)
        self._rules.append((number_pattern, number_format))

        # String format
        string_format = QTextCharFormat()
        string_pattern = QRegExp("\'.*\'")
        string_pattern.setMinimal(True)
        string_format.setForeground(Qt.darkMagenta)
        self._rules.append((string_pattern, string_format))

        # Comment format
        comment_format = QTextCharFormat()
        comment_pattern = QRegExp("%[^\n]*")
        comment_format.setForeground(Qt.darkGreen)
        self._rules.append((comment_pattern, comment_format))

        # Paren
        self.paren = QRegExp('\(|\)')
开发者ID:centaurialpha,项目名称:pireal,代码行数:35,代码来源:highlighter.py

示例14: __init__

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setForeground [as 别名]
    def __init__(self, parent=None):
        super().__init__(parent)

        quotationFormat = QTextCharFormat()
        quotationFormat.setForeground(QColor(255, 27, 147))
        self.addBlockRule('u?r?"""', '"""', quotationFormat)
        self.addBlockRule("u?r?'''", "'''", quotationFormat)

        singleLineCommentFormat = QTextCharFormat()
        singleLineCommentFormat.setForeground(QColor(112, 128, 144))
        self.addRule("#[^\n]*", singleLineCommentFormat)

        quotationTemplate = "{0}[^{0}\\\\]*(\\\\.[^{0}\\\\]*)*{0}"
        self.addRule(
            "|".join(quotationTemplate.format(char) for char in ("'", "\"")),
            quotationFormat)

        classOrFnNameFormat = QTextCharFormat()
        classOrFnNameFormat.setForeground(QColor(96, 106, 161))
        self.addRule(
            "(?<=\\bclass\\s|def\\s\\b)\\s*(\\w+)", classOrFnNameFormat)

        keywordFormat = QTextCharFormat()
        keywordFormat.setForeground(QColor(45, 95, 235))
        self.addRule("\\b(%s)\\b" % ("|".join(kwlist)), keywordFormat)
开发者ID:anthrotype,项目名称:trufont,代码行数:27,代码来源:scriptingWindow.py

示例15: format

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setForeground [as 别名]
def format(color, style=''):
    """Return a QTextCharFormat with the given attributes.
    """
    _color = QColor()
    _color.setNamedColor(color)

    _format = QTextCharFormat()
    _format.setForeground(_color)
    if 'bold' in style:
        _format.setFontWeight(QFont.Bold)
    if 'italic' in style:
        _format.setFontItalic(True)

    return _format
开发者ID:cinepost,项目名称:Copperfield_FX,代码行数:16,代码来源:python_syntax_highlighter.py


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