qtqpushbuttonqtexteditqtextcursor

How to move the QTextCursor from QTextEdit to another QTextEdit?


How to move the QTextCursor from QTextEdit to another QTextEdit? Here is my code:

self.textedit = QTextEdit(MainWindow)
self.textedit_2 = QTextEdit(MainWindow)
self.cursor = self.textedit.textCursor()
self.button.clicked.connect(self.moveCursor)

def moveCursor(self):
    self.textedit_2.setTextCursor(self.cursor)

Solution

  • the cursor is related to the focus on the widget so you need to set the focus first

    textedit_2.setFocus()