Python 3.x PyQt或PySide:QTextEdit取消选择全部
我正在使用PySide(PyQt也可以),我想取消选择QTextEdit中的所有内容。选择所有内容都非常简单,它由self.textedit.selectAll()完成,但我找不到一种简单的方法来取消选择所有内容。有没有一种我不知道的简单方法,或者比这更复杂 谢谢。也一样,不是吗Python 3.x PyQt或PySide:QTextEdit取消选择全部,python-3.x,pyqt,pyside,qtextedit,deselect,Python 3.x,Pyqt,Pyside,Qtextedit,Deselect,我正在使用PySide(PyQt也可以),我想取消选择QTextEdit中的所有内容。选择所有内容都非常简单,它由self.textedit.selectAll()完成,但我找不到一种简单的方法来取消选择所有内容。有没有一种我不知道的简单方法,或者比这更复杂 谢谢。也一样,不是吗 QLineEdit.deselect(self)Text对象中的所有内容 榜样 . myQLineEdit = QLineEdit() . . myQLineEdit .selectAll() . . myQLineE
QLineEdit.deselect(self)
Text对象中的所有内容
榜样
.
myQLineEdit = QLineEdit()
.
.
myQLineEdit .selectAll()
.
.
myQLineEdit.deselect()
.
参考:
或者,如果您想取消选择所有
QLineEdit
,您的刚找到的子项是一个QLineEdit
,并取消选择所有项
myQWidget= QWidget()
.
.
listsMyQLineEdit = myQWidget.findChildren(QLineEdit)
for myQLineEdit in listsMyQLineEdit:
myQLineEdit.deselect()
.
.
关于,您想首先获取
qtexedit
的QTextCursor
my_text_cursor = my_text_edit.textCursor()
然后清除所选的QTextCursor
my_text_cursor.clearSelection()
然后使用新的QTextCursor
更新QLineEdit
(请参见QTextEdit.textCursor()
,这表示更新返回的QTextCursor
实际上不会影响QTextCursor
,除非您还调用以下命令)
这仅适用于QLineEdit,因为某些奇怪的原因,QTextEdit没有这种功能…谢谢,这非常有效。但真的很奇怪,QTextEdit没有一个很好的方法来取消选择所有内容,而QLineEdit有。。。
my_text_edit.setTextCursor(my_text_cursor)