本文整理汇总了Python中PyQt4.QtGui.QTextCursor.selection方法的典型用法代码示例。如果您正苦于以下问题:Python QTextCursor.selection方法的具体用法?Python QTextCursor.selection怎么用?Python QTextCursor.selection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QTextCursor
的用法示例。
在下文中一共展示了QTextCursor.selection方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: show
# 需要导入模块: from PyQt4.QtGui import QTextCursor [as 别名]
# 或者: from PyQt4.QtGui.QTextCursor import selection [as 别名]
def show(cursor, pos=None, num_lines=6):
"""Displays a tooltip showing part of the cursor's Document.
If the cursor has a selection, those blocks are displayed.
Otherwise, num_lines lines are displayed.
If pos is not given, the global mouse position is used.
"""
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() * .8)
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))
label = QLabel()
label.setPixmap(pix)
label.setStyleSheet("QLabel { border: 1px solid #777; }")
label.resize(size)
widgets.customtooltip.show(label, pos)
示例2: isBlankAfter
# 需要导入模块: from PyQt4.QtGui import QTextCursor [as 别名]
# 或者: from PyQt4.QtGui.QTextCursor import selection [as 别名]
def isBlankAfter(cursor):
"""Returns True if there's no text on the current line after the cursor."""
if cursor.hasSelection():
return False
if cursor.atBlockEnd():
return True
c = QTextCursor(cursor)
c.movePosition(QTextCursor.EndOfBlock, QTextCursor.KeepAnchor)
return c.selection().toPlainText().isspace()
示例3: isBlankBefore
# 需要导入模块: from PyQt4.QtGui import QTextCursor [as 别名]
# 或者: from PyQt4.QtGui.QTextCursor import selection [as 别名]
def isBlankBefore(cursor):
"""Returns True if there's no text on the current line before the cursor."""
if cursor.hasSelection():
return False
if cursor.atBlockStart():
return True
c = QTextCursor(cursor)
c.movePosition(QTextCursor.StartOfBlock, QTextCursor.KeepAnchor)
return c.selection().toPlainText().isspace()