I want to change only a part of my text, basically I want it so that if a user makes a typo my program auto-corrects it. Now my code just resets the whole text to change the typo.
Here is my code
class MainEditor(QtWidgets.QTextEdit):
def __init__(self):
super().__init__()
self.textChanged.connect(self.current_text)
self.just_changed = False
def current_text(self):
if not self.just_changed:
whole = self.toPlainText()
whole = whole.split(' ')
if len(whole) >= 2:
last_word = whole[-2]
# here was some logic I am just taking it as stop and assuming it was typo
correct_word = "stop"
whole[-2] = correct_word
self.just_changed = True
self.setText(' '.join(whole))
else:
self.just_changed = False
As you see it retypes the whole text again to fix one typo is there a way to only change a part of the text in PySide6?
ADDITIONAL INFO:
This class object is then added to a QVBoxLayout and then the QVBoxLayout is added to the main QVBoxLayout and then it is added to QtWidgets.QWidget and I am also using the setHtml feature changing it to bold.