PyQt or PySide: QTextEdit deselect all

允我心安 提交于 2019-12-19 09:26:37

问题


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?

Thanks.


回答1:


You want to first get the QTextCursor for the QTextEdit

my_text_cursor = my_text_edit.textCursor()

Then clear the selection of the QTextCursor

my_text_cursor.clearSelection()

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)



回答2:


It same too, isn't it?

QLineEdit.deselect (self) Text all in your object.

Example;

.
myQLineEdit = QLineEdit()
.
.
myQLineEdit .selectAll()
.
.
myQLineEdit.deselect()
.

Reference : http://pyqt.sourceforge.net/Docs/PyQt4/qlineedit.html#deselect


Or, did your want to deselect all QLineEdit, your just find Children is a QLineEdit and deselect it all;

myQWidget= QWidget()
.
.
listsMyQLineEdit = myQWidget.findChildren(QLineEdit)
for myQLineEdit in listsMyQLineEdit:
    myQLineEdit.deselect()
.
.

Regards,



来源:https://stackoverflow.com/questions/25347825/pyqt-or-pyside-qtextedit-deselect-all

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!