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
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)
def change_cursor_info(self, data: QTextCursor): ss = data.selectionStart() se = data.selectionEnd() selected_info = "" if se - ss: selected_info = "{0} {1} ".format( se - ss, "char" if (se - ss) == 1 else "chars") self.showMessage("{0}{1}:{2}".format(selected_info, data.blockNumber(), data.columnNumber()))
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)
def lineNumberAreaPaintEvent(self, event): painter = QPainter(self.lineNumberArea) painter.fillRect(event.rect(), Qt.cyan) 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(Qt.darkCyan) 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)
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)