当前位置: 首页>>代码示例>>Python>>正文


Python QTextCursor.blockNumber方法代码示例

本文整理汇总了Python中PyQt5.QtGui.QTextCursor.blockNumber方法的典型用法代码示例。如果您正苦于以下问题:Python QTextCursor.blockNumber方法的具体用法?Python QTextCursor.blockNumber怎么用?Python QTextCursor.blockNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtGui.QTextCursor的用法示例。


在下文中一共展示了QTextCursor.blockNumber方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: lineNumberAreaWidth

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import blockNumber [as 别名]
	def lineNumberAreaWidth(self):
		if not globalSettings.lineNumbersEnabled:
			return 0
		cursor = QTextCursor(self.document())
		cursor.movePosition(QTextCursor.End)
		if globalSettings.relativeLineNumbers:
			digits = len(str(cursor.blockNumber())) + 1
		else:
			digits = len(str(cursor.blockNumber() + 1))
		return 5 + self.fontMetrics().width('9') * digits
开发者ID:starofrainnight,项目名称:retext,代码行数:12,代码来源:editor.py

示例2: lineNumberAreaPaintEvent

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import blockNumber [as 别名]
	def lineNumberAreaPaintEvent(self, event):
		painter = QPainter(self.lineNumberArea)
		painter.fillRect(event.rect(), colorValues['lineNumberArea'])
		cursor = QTextCursor(self.document())
		cursor.movePosition(QTextCursor.Start)
		atEnd = False
		while not atEnd:
			rect = self.cursorRect(cursor)
			block = cursor.block()
			if block.isVisible():
				number = str(cursor.blockNumber() + 1)
				painter.setPen(colorValues['lineNumberAreaText'])
				painter.drawText(0, rect.top(), self.lineNumberArea.width()-2,
					self.fontMetrics().height(), Qt.AlignRight, number)
			cursor.movePosition(QTextCursor.EndOfBlock)
			atEnd = cursor.atEnd()
			if not atEnd:
				cursor.movePosition(QTextCursor.NextBlock)
开发者ID:Tamriel,项目名称:retext,代码行数:20,代码来源:editor.py

示例3: paintEvent

# 需要导入模块: from PyQt5.QtGui import QTextCursor [as 别名]
# 或者: from PyQt5.QtGui.QTextCursor import blockNumber [as 别名]
	def paintEvent(self, event):
		if not globalSettings.lineNumbersEnabled:
			return QWidget.paintEvent(self, event)
		painter = QPainter(self)
		painter.fillRect(event.rect(), colorValues['lineNumberArea'])
		cursor = QTextCursor(self.editor.document())
		cursor.movePosition(QTextCursor.Start)
		atEnd = False
		if globalSettings.relativeLineNumbers:
			relativeTo = self.editor.textCursor().blockNumber()
		else:
			relativeTo = -1
		while not atEnd:
			rect = self.editor.cursorRect(cursor)
			block = cursor.block()
			if block.isVisible():
				number = str(cursor.blockNumber() - relativeTo).replace('-', '−')
				painter.setPen(colorValues['lineNumberAreaText'])
				painter.drawText(0, rect.top(), self.width() - 2,
					self.fontMetrics().height(), Qt.AlignRight, number)
			cursor.movePosition(QTextCursor.EndOfBlock)
			atEnd = cursor.atEnd()
			if not atEnd:
				cursor.movePosition(QTextCursor.NextBlock)
开发者ID:cufrancis,项目名称:retext,代码行数:26,代码来源:editor.py


注:本文中的PyQt5.QtGui.QTextCursor.blockNumber方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。