本文整理汇总了Python中PyQt5.QtGui.QTextCursor.selection方法的典型用法代码示例。如果您正苦于以下问题:Python QTextCursor.selection方法的具体用法?Python QTextCursor.selection怎么用?Python QTextCursor.selection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QTextCursor
的用法示例。
在下文中一共展示了QTextCursor.selection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_minimap_doc
# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import selection [as 别名]
def update_minimap_doc(self, position, charsRemoved, charsAdded):
def select_blocks(first_block, last_block):
first_block_pos = first_block.position()
doc_cursor.setPosition(first_block_pos)
last_block_pos = last_block.position()
doc_cursor.setPosition(last_block_pos, QTextCursor.KeepAnchor)
doc_cursor.movePosition(
QTextCursor.EndOfBlock, QTextCursor.KeepAnchor)
print("selected text :", doc_cursor.selectedText())
return doc_cursor.selectedText()
doc_cursor = QTextCursor(self._doc)
minimap_cursor = QTextCursor(self._minimap_doc)
# IF one same block is modified
if self._minimap_doc.blockCount() == self._doc.blockCount():
doc_cursor.setPosition(position)
doc_cursor.select(QTextCursor.BlockUnderCursor)
minimap_cursor.setPosition(position)
minimap_cursor.select(QTextCursor.BlockUnderCursor)
minimap_cursor.insertFragment(doc_cursor.selection())
# TODO: if the doc is modified on more than one block but resulting in
# the same count of blocks (right now only the first block would be
# updated)
else:
# ELSE
doc_cursor.select(QTextCursor.Document)
minimap_cursor.select(QTextCursor.Document)
minimap_cursor.insertFragment(doc_cursor.selection())
示例2: pixmap
# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import selection [as 别名]
def pixmap(cursor, num_lines=6, scale=0.8):
"""Return a QPixmap displaying the selected lines of the document.
If the cursor has no selection, num_lines are drawn.
By default the text is drawn 0.8 * the normal font size. You can change
that by supplying the scale parameter.
"""
block = cursor.document().findBlock(cursor.selectionStart())
c2 = QTextCursor(block)
if cursor.hasSelection():
c2.setPosition(cursor.selectionEnd(), QTextCursor.KeepAnchor)
c2.movePosition(QTextCursor.EndOfBlock, QTextCursor.KeepAnchor)
else:
c2.movePosition(QTextCursor.NextBlock, QTextCursor.KeepAnchor, num_lines)
data = textformats.formatData('editor')
doc = QTextDocument()
font = QFont(data.font)
font.setPointSizeF(font.pointSizeF() * scale)
doc.setDefaultFont(font)
doc.setPlainText(c2.selection().toPlainText())
if metainfo.info(cursor.document()).highlighting:
highlighter.highlight(doc, state=tokeniter.state(block))
size = doc.size().toSize() + QSize(8, -4)
pix = QPixmap(size)
pix.fill(data.baseColors['background'])
doc.drawContents(QPainter(pix))
return pix