本文整理汇总了Python中PySide.QtCore.QRegExp.matchedLength方法的典型用法代码示例。如果您正苦于以下问题:Python QRegExp.matchedLength方法的具体用法?Python QRegExp.matchedLength怎么用?Python QRegExp.matchedLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtCore.QRegExp
的用法示例。
在下文中一共展示了QRegExp.matchedLength方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: highlightBlock
# 需要导入模块: from PySide.QtCore import QRegExp [as 别名]
# 或者: from PySide.QtCore.QRegExp import matchedLength [as 别名]
def highlightBlock(self, text):
for rule in self.highlighting_rules:
expression = QRegExp(rule.pattern)
index = expression.indexIn(text)
while index >= 0:
length = expression.matchedLength()
self.setFormat(index, length, rule.format)
index = expression.indexIn(text, index+length)
self.setCurrentBlockState(0)
示例2: highlightBlock
# 需要导入模块: from PySide.QtCore import QRegExp [as 别名]
# 或者: from PySide.QtCore.QRegExp import matchedLength [as 别名]
def highlightBlock(self, text):
# Derived from Qt function, used to apply color-syntaxing to text
# :param text: text input
rules = [(QColor(100, 165, 225), r"^(//|#).+$"), #blue 100, 165, 225
(QColor(205, 200, 120), r"^(//|#) Warning.+$"), #yellow 205, 200, 120
(QColor(165, 75, 75), r"^(//|#).+Error.+$"), #red 165, 75, 75
(QColor(115, 215, 150), r"^(//|#).+Result.+$")] #green 115, 215, 150
# loop through rules
for color, pattern in rules:
keyword = QTextCharFormat()
keyword.setForeground(color)
# get regexp pattern
expression = QRegExp(pattern)
index = expression.indexIn(text)
# loop until all matches are done
while index >= 0:
length = expression.matchedLength()
# format text with current formatting
self.setFormat(index, length, keyword)
index = expression.indexIn(text, index + length)
self.setCurrentBlockState(0)