Ishara Dayarathna
Ishara Dayarathna

Reputation: 3601

Python - pyqt5 - clear selections of QTextBrowser

I want to clear the selection in QTextBrowser (clear the highlighting).

self.textBrowser.textCursor().clearSelection()

Above code is not working for me.

Upvotes: 0

Views: 1559

Answers (1)

MalloyDelacroix
MalloyDelacroix

Reputation: 2293

Try this:

cursor = self.textBrowser.textCursor()
cursor.clearSelection()
self.textBrowser.setTextCursor(cursor)

The cursor that is returned by self.textBrowser.textCursor() is only a copy of the textCursor being used. To apply the changes to the text browser, you must operate on the copy and then set the text browsers textCursor to the modified version.

Upvotes: 3

Related Questions