I'm writing a screenwriting application with PySide. What I want is to turn the characters to uppercase while the user is typing.
The following piece of code gives a runtime error saying "maximum recursion depth exceeded" every time I add a character. I get what it means and why it's happening but is there a different way?
self.cursor = self.recipient.textCursor()
self.cursor.movePosition(QTextCursor.StartOfLine)
self.cursor.movePosition(QTextCursor.EndOfLine, QTextCursor.KeepAnchor)
self.curtext = self.cursor.selectedText()
if len(self.curtext) > len(self.prevText):
self.cursor.insertText(self.curtext.upper())
self.cursor.clearSelection()
self.prevText = self.curtext
The code above runs whenever the text in the text edit widget is changed. The if statment prevents the code from running when the user hasn't insert text.