How to move the QTextCursor from QTextEdit to another QTextEdit?

166 views Asked by At

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)
2

There are 2 answers

1
ΦXocę 웃 Пepeúpa ツ On BEST ANSWER

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

textedit_2.setFocus()
0
zaldy123098 On
self.textedit = QTextEdit(MainWindow)
self.textedit_2 = QTextEdit(MainWindow)
self.cursor = self.textedit.textCursor()
self.button.clicked.connect(self.moveCursor)

def moveCursor(self):
    self.cursor = self.textedit_2.textCursor()
    self.textedit_2.setFocus()
    self.tetxtedit_2.setTextCursor(self.cursor)