PyQt or PySide: QTextEdit deselect all
Asked Answered
N

2

5

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.

Nielson answered 17/8, 2014 at 9:11 Comment(0)
F
6

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)
Fluorescence answered 17/8, 2014 at 10:57 Comment(1)
Thanks, that works great. But it's strange really, QTextEdit not having a good way to deselect everything while QLineEdit has...Nielson
U
1

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,

Unlikelihood answered 17/8, 2014 at 10:37 Comment(1)
That's true only for QLineEdit, QTextEdit doesn't have that for some strange reason...Nielson

© 2022 - 2024 — McMap. All rights reserved.