PyQt 或 PySide:QTextEdit 取消全选 [英] PyQt or PySide: QTextEdit deselect all

查看:46
本文介绍了PyQt 或 PySide:QTextEdit 取消全选的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using PySide(PyQt is fine as well) and I want to deselect everything inside a QTextEdit. Selecting everything is very easy and it's done by self.textedit.selectAll(), but I can't find a simple way to deselect everything. Is there a straightforward way to do it that I'm not aware of or is it more complicated than that?

谢谢.

推荐答案

您想先为 QTextEdit

my_text_cursor = my_text_edit.textCursor()

然后清除QTextCursor

my_text_cursor.clearSelection()

然后使用新的 QTextCursor 更新 QLineEdit(参见 documentation 表示更新返回的 QTextCursor 实际上并不影响 QTextEdit 除非你也调用以下)

Then update the QLineEdit with the new QTextCursor (see documentation for QTextEdit.textCursor() which indicates updating the returned QTextCursor does not actually affect the QTextEdit unless you also call the following)

my_text_edit.setTextCursor(my_text_cursor)

这篇关于PyQt 或 PySide:QTextEdit 取消全选的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆