Select Text Of Textedit Object With Qtextcursor, Qtextedit
I have a textEdit field and I want to process some selected text within this field (but not the format of it). So far, I connect the button with: QtCore.QObject.connect(self.ui.myt
Solution 1:
Answering my own question. Posting here for fellow Python noobs:
Get the selected text:
cursor = self.ui.editor_window.textCursor()
textSelected = cursor.selectedText()
insert back the text into your editor.
self.ui.editor_window.append(s)
There are also alternatives to append(), for inserting the text into the original text. So, to put a selected text into uppercase:
defmytext(self):
cursor = self.ui.editor_window.textCursor()
textSelected = cursor.selectedText()
s = textSelected.upper()
self.ui.editor_window.append(s)
Post a Comment for "Select Text Of Textedit Object With Qtextcursor, Qtextedit"