这些是我的小工具,
self.recipient = QTextEdit(self)
self.document = QTextDocument(self)
self.recipient.setDocument(self.document)
self.cursor = QTextCursor(self.document)我想要做的是使用QTextCursor在我的QTextEdit中复制选定的文本。我尝试过函数selectedText(),但它给了我一个空字符串。下面是我尝试打印的方法:
print('%s' % (self.cursor.selectedText()))发布于 2014-12-28 18:13:25
您需要从文本编辑中检索当前游标:
cursor = self.recipient.textCursor()
print('%s' % (cursor.selectedText()))但请注意,此游标仅为副本。如果对其进行更改,这些更改将不会立即更新文本编辑。为此,您需要重置光标,如下所示:
# make some changes to the cursor
cursor.select(QtGui.QTextCursor.LineUnderCursor)
# update the text-edit
self.recipient.setTextCursor(cursor)https://stackoverflow.com/questions/27678445
复制相似问题