简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM