本文整理汇总了Python中PyQt5.QtGui.QTextCharFormat.setFontWeight方法的典型用法代码示例。如果您正苦于以下问题:Python QTextCharFormat.setFontWeight方法的具体用法?Python QTextCharFormat.setFontWeight怎么用?Python QTextCharFormat.setFontWeight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QTextCharFormat
的用法示例。
在下文中一共展示了QTextCharFormat.setFontWeight方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontWeight [as 别名]
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("-->")
示例2: __init__
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontWeight [as 别名]
def __init__(self, parent=None):
super(Highlighter, self).__init__(parent)
keywordFormat = QTextCharFormat()
keywordFormat.setForeground(Qt.darkBlue)
keywordFormat.setFontWeight(QFont.Bold)
keywordPatterns = ["""</?\w+\s+[^>]*>""","<[/]?(html|body|head|title|div|a|br|form|input|b|p|i|center|span|font|table|tr|td|h[1-6])[/]?>"]
self.highlightingRules = [(QRegExp(pattern), keywordFormat)
for pattern in keywordPatterns]
self.multiLineCommentFormat = QTextCharFormat()
self.multiLineCommentFormat.setForeground(Qt.red)
quotationFormat = QTextCharFormat()
quotationFormat.setForeground(Qt.darkGreen)
self.highlightingRules.append((QRegExp("\".*\""),
quotationFormat))
functionFormat = QTextCharFormat()
functionFormat.setFontItalic(True)
functionFormat.setForeground(Qt.blue)
self.highlightingRules.append((QRegExp("\\b[A-Za-z0-9_]+(?=\\()"),
functionFormat))
moreKeyWords = QTextCharFormat()
moreKeyWords.setForeground(Qt.darkMagenta)
moreKeyWords.setFontWeight(QFont.Bold)
self.highlightingRules.append((QRegExp("(id|class|src|border|width|height|style|name|type|value)="),moreKeyWords))
self.commentStartExpression = QRegExp("<!--")
self.commentEndExpression = QRegExp("-->")
示例3: __init__
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontWeight [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('\(|\)')
示例4: highlightBlock
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontWeight [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)
示例5: _get_bold
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontWeight [as 别名]
def _get_bold(self):
_format = QTextCharFormat()
if self.textCursor().charFormat().font().bold():
_format.setFontWeight(QFont.Normal)
else:
_format.setFontWeight(QFont.Bold)
return _format
示例6: addTestResult
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontWeight [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())
示例7: reformatHeaders
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontWeight [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)
示例8: format
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontWeight [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
示例9: logformats
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontWeight [as 别名]
def logformats(self):
"""Returns a dictionary with QTextCharFormats for the different types of messages.
Besides the STDOUT, STDERR, NEUTRAL, FAILURE and SUCCESS formats there is also
a "link" format, that looks basically the same as the output formats, but blueish
and underlined, to make parts of the output (e.g. filenames) look clickable.
"""
textColor = QApplication.palette().color(QPalette.WindowText)
successColor = qutil.addcolor(textColor, 0, 128, 0) # more green
failureColor = qutil.addcolor(textColor, 128, 0, 0) # more red
linkColor = qutil.addcolor(textColor, 0, 0, 128) # more blue
stdoutColor = qutil.addcolor(textColor, 64, 64, 0) # more purple
s = QSettings()
s.beginGroup("log")
outputFont = QFont(s.value("fontfamily", "monospace", str))
outputFont.setPointSizeF(s.value("fontsize", 9.0, float))
output = QTextCharFormat()
output.setFont(outputFont)
# enable zooming the log font size
output.setProperty(QTextFormat.FontSizeAdjustment, 0)
stdout = QTextCharFormat(output)
stdout.setForeground(stdoutColor)
stderr = QTextCharFormat(output)
link = QTextCharFormat(output)
link.setForeground(linkColor)
link.setFontUnderline(True)
status = QTextCharFormat()
status.setFontWeight(QFont.Bold)
neutral = QTextCharFormat(status)
success = QTextCharFormat(status)
success.setForeground(successColor)
failure = QTextCharFormat(status)
failure.setForeground(failureColor)
return {
job.STDOUT: stdout,
job.STDERR: stderr,
job.NEUTRAL: neutral,
job.SUCCESS: success,
job.FAILURE: failure,
'link': link,
}
示例10: highlightBlock
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontWeight [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)
示例11: format
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontWeight [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
示例12: eltToStyle
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontWeight [as 别名]
def eltToStyle(elt):
fmt = QTextCharFormat()
if elt.get('bold'):
fmt.setFontWeight(QFont.Bold if toBool(elt.get('bold')) else QFont.Normal)
if elt.get('italic'):
fmt.setFontItalic(toBool(elt.get('italic')))
if elt.get('underline'):
fmt.setFontUnderline(toBool(elt.get('underline')))
if elt.get('textColor'):
fmt.setForeground(QColor(elt.get('textColor')))
if elt.get('backgroundColor'):
fmt.setBackground(QColor(elt.get('backgroundColor')))
if elt.get('underlineColor'):
fmt.setUnderlineColor(QColor(elt.get('underlineColor')))
return fmt
示例13: __init__
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontWeight [as 别名]
def __init__(self, parent=None):
super(FeatureTextHighlighter, self).__init__(parent)
keywordFormat = QTextCharFormat()
keywordFormat.setForeground(QColor(34, 34, 34))
keywordFormat.setFontWeight(QFont.Bold)
self.highlightingRules.append(("\\b(%s)\\b" % ("|".join(keywordPatterns)), keywordFormat))
singleLineCommentFormat = QTextCharFormat()
singleLineCommentFormat.setForeground(Qt.darkGray)
self.highlightingRules.append(("#[^\n]*", singleLineCommentFormat))
groupFormat = QTextCharFormat()
groupFormat.setFontWeight(QFont.Bold)
groupFormat.setForeground(QColor(96, 106, 161))
self.highlightingRules.append(("@[A-Za-z0-9_.]+", groupFormat))
示例14: char_format
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontWeight [as 别名]
def char_format(color, style=[]):
q_color = QColor()
if type(color) == str:
q_color.setNamedColor(color)
elif type(color) == tuple:
q_color.setRgb(*color)
q_format = QTextCharFormat()
q_format.setForeground(q_color)
if 'bold' in style:
q_format.setFontWeight(QFont.Bold)
if 'italic' in style:
q_format.setFontItalic(True)
return q_format
示例15: __init__
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontWeight [as 别名]
def __init__(self, parent=None):
super(Highlighter, self).__init__(parent)
keywordFormat = QTextCharFormat()
keywordFormat.setForeground(Qt.darkBlue)
keywordFormat.setFontWeight(QFont.Bold)
keywordPatterns = ["\\bchar\\b", "\\bclass\\b", "\\bconst\\b",
"\\bdouble\\b", "\\benum\\b", "\\bexplicit\\b", "\\bfriend\\b",
"\\binline\\b", "\\bint\\b", "\\blong\\b", "\\bnamespace\\b",
"\\boperator\\b", "\\bprivate\\b", "\\bprotected\\b",
"\\bpublic\\b", "\\bshort\\b", "\\bsignals\\b", "\\bsigned\\b",
"\\bslots\\b", "\\bstatic\\b", "\\bstruct\\b",
"\\btemplate\\b", "\\btypedef\\b", "\\btypename\\b",
"\\bunion\\b", "\\bunsigned\\b", "\\bvirtual\\b", "\\bvoid\\b",
"\\bvolatile\\b"]
self.highlightingRules = [(QRegExp(pattern), keywordFormat)
for pattern in keywordPatterns]
classFormat = QTextCharFormat()
classFormat.setFontWeight(QFont.Bold)
classFormat.setForeground(Qt.darkMagenta)
self.highlightingRules.append((QRegExp("\\bQ[A-Za-z]+\\b"),
classFormat))
singleLineCommentFormat = QTextCharFormat()
singleLineCommentFormat.setForeground(Qt.red)
self.highlightingRules.append((QRegExp("//[^\n]*"),
singleLineCommentFormat))
self.multiLineCommentFormat = QTextCharFormat()
self.multiLineCommentFormat.setForeground(Qt.red)
quotationFormat = QTextCharFormat()
quotationFormat.setForeground(Qt.darkGreen)
self.highlightingRules.append((QRegExp("\".*\""), quotationFormat))
functionFormat = QTextCharFormat()
functionFormat.setFontItalic(True)
functionFormat.setForeground(Qt.blue)
self.highlightingRules.append((QRegExp("\\b[A-Za-z0-9_]+(?=\\()"),
functionFormat))
self.commentStartExpression = QRegExp("/\\*")
self.commentEndExpression = QRegExp("\\*/")