本文整理汇总了Python中PyQt5.QtGui.QTextCursor.isNull方法的典型用法代码示例。如果您正苦于以下问题:Python QTextCursor.isNull方法的具体用法?Python QTextCursor.isNull怎么用?Python QTextCursor.isNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QTextCursor
的用法示例。
在下文中一共展示了QTextCursor.isNull方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: slotCursorPositionChanged
# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import isNull [as 别名]
def slotCursorPositionChanged(self):
"""Called whenever the cursor position changes.
Highlights matching characters if the cursor is at one of them.
"""
cursor = self.edit().textCursor()
block = cursor.block()
text = block.text()
# try both characters at the cursor
col = cursor.position() - block.position()
end = col + 1
col = max(0, col - 1)
for c in text[col:end]:
if c in self.matchPairs:
break
col += 1
else:
self.clear()
return
# the cursor is at a character from matchPairs
i = self.matchPairs.index(c)
cursor.setPosition(block.position() + col)
# find the matching character
new = QTextCursor(cursor)
if i & 1:
# look backward
match = self.matchPairs[i - 1]
flags = QTextDocument.FindBackward
else:
# look forward
match = self.matchPairs[i + 1]
flags = QTextDocument.FindFlags()
new.movePosition(QTextCursor.Right)
# search, also nesting
rx = QRegExp(QRegExp.escape(c) + "|" + QRegExp.escape(match))
nest = 0
while nest >= 0:
new = cursor.document().find(rx, new, flags)
if new.isNull():
self.clear()
return
nest += 1 if new.selectedText() == c else -1
cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor)
self.highlight([cursor, new])