def METHOD_NAME(self, edit):
    old = self._textedit
    if edit is old:
        return
    if old:
        # disconnect old textedit
        self.clearCursor()
        old.removeEventFilter(self)
        old.cursorPositionChanged.disconnect(self.updateCursorPosition)
        old.selectionChanged.disconnect(self.updateCursorPosition)
        old.setCursorWidth(self._originalCursorWidth)
    self._textedit = edit
    if edit:
        # connect new textedit
        edit.installEventFilter(self)
        edit.cursorPositionChanged.connect(self.updateCursorPosition)
        edit.selectionChanged.connect(self.updateCursorPosition)
        self._originalCursorWidth = edit.cursorWidth()
    self.setMode(NORMAL)
    if edit:
        self.updateCursorPosition()