我正在使用 PySide(PyQt 也很好)并且我想取消选择 QTextEdit 中的所有内容。选择所有内容非常简单,它是通过 self.textedit.selectAll() 完成的,但我找不到取消选择所有内容的简单方法。有没有一种我不知道的直接方法,或者比这更复杂?

谢谢。

最佳答案

您想首先获取 QTextCursorQTextEdit

my_text_cursor = my_text_edit.textCursor()

然后清除QTextCursor的选择
my_text_cursor.clearSelection()

然后用新的 QLineEdit 更新 QTextCursor(参见 documentationQTextEdit.textCursor(),这表明更新返回的 QTextCursor 实际上不会影响 QTextEdit,除非你也调用以下代码)
my_text_edit.setTextCursor(my_text_cursor)

关于python-3.x - PyQt 或 PySide : QTextEdit deselect all,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25347825/

10-11 21:49