本文整理汇总了Python中PyQt4.QtGui.QTextCursor.positionInBlock方法的典型用法代码示例。如果您正苦于以下问题:Python QTextCursor.positionInBlock方法的具体用法?Python QTextCursor.positionInBlock怎么用?Python QTextCursor.positionInBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QTextCursor
的用法示例。
在下文中一共展示了QTextCursor.positionInBlock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _decorate
# 需要导入模块: from PyQt4.QtGui import QTextCursor [as 别名]
# 或者: from PyQt4.QtGui.QTextCursor import positionInBlock [as 别名]
def _decorate(self, decoration):
c = QTextCursor(self.block)
spos = c.positionInBlock()
if decoration.count(" ") == len(decoration):
c.insertText(decoration)
else:
c.insertHtml(decoration)
self.decorated = True
self.decoration_len = c.positionInBlock()-spos
self.active_area_start = self.decoration_len
示例2: get_tooltip
# 需要导入模块: from PyQt4.QtGui import QTextCursor [as 别名]
# 或者: from PyQt4.QtGui.QTextCursor import positionInBlock [as 别名]
def get_tooltip(self, pos):
cursor_pos = self.document().documentLayout().hitTest(QtCore.QPointF(pos), Qt.Qt.ExactHit)
if cursor_pos == -1:
return "", QRect()
cursor = QTextCursor(self.document())
cursor.setPosition(cursor_pos)
col = cursor.positionInBlock()
line = cursor.blockNumber()
tooltip = ""
rect = QRect()
if line >= len(self.highlighter.matches):
return "", QRect()
match_start = 0
match_len = 0
matches = 0
#for word in self.highlighter.matches[line]:
#if col >= word[1] and col < word[2]:
for word in self.words_at_pos(line, col):
keyword = word[0]
# Go for the smallest region possible so we can update
# as soon as the mouse falls out of range of one of the words.
if word[1] > match_start:
match_start = word[1]
if word[2] - word[1] < match_len:
match_len = word[2] - word[1]
if matches > 0:
tooltip += u"\n"
if not keyword.section == "":
tooltip += u"【%s】 " % keyword.section
tooltip += u"%s ― %s" % (keyword.word, keyword.meaning)
matches += 1
# Highlight our word, so we can get the rect.
cursor.movePosition(QTextCursor.Start)
for i in range(line):
cursor.movePosition(QTextCursor.NextBlock)
for i in range(match_start):
cursor.movePosition(QTextCursor.NextCharacter)
for i in range(match_len):
cursor.movePosition(QTextCursor.NextCharacter, QTextCursor.KeepAnchor)
rect = self.cursorRect(cursor)
return tooltip, rect