1

如何将 QTextCursor 从 QTextEdit 移动到另一个 QTextEdit?这是我的代码:

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

2 回答 2

0

光标与小部件上的焦点有关,因此您需要先设置焦点

textedit_2.setFocus()
于 2020-09-13T09:31:09.477 回答
0
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)
于 2020-09-15T11:49:43.453 回答