def overwrite_text(cursor, text):
text_length = len(text)
cursor.clearSelection()
# Select the text after the current position (if any)
current_position = cursor.position()
cursor.movePosition(QTextCursor.Right,
mode=QTextCursor.MoveAnchor,
n=text_length)
cursor.movePosition(QTextCursor.Left,
mode=QTextCursor.KeepAnchor,
n=cursor.position()-current_position)
# Insert the text (will overwrite the selected text)
cursor.insertText(text)
评论列表
文章目录