Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with QTextEdit cursor, when using eventFilters

I am facing an issue with QTextEdit. i am using eventFilters for QTextEdit. When i press keys in the numpad (0-9) in the QTextEdit it will auto compleate the sentense which is connected that number. For example

enter image description here

Everything is working fine but when i type a sentence and press the number 3 in numpad the text related to it is filled in QTextEdit but the cursor is moved to home. actually it is supposed to be the place where the sentence end.

enter image description here

Can anyone guide me how to deal with this.

Thanks and Regards,
Sudeepth Patinjarayil.

like image 397
Sudeepth Patinjarayil Avatar asked Jan 30 '26 04:01

Sudeepth Patinjarayil


1 Answers

You just need to move the cursor to the end of the document, checkout this example:

#!/usr/bin/env python
#-*- coding:utf-8 -*-

from PyQt4 import QtGui, QtCore

class MyWindow(QtGui.QTextEdit):
    def __init__(self, parent=None):
        super(MyWindow, self).__init__(parent)

        self.setPlainText("Hello!")

        cursor = self.textCursor()
        cursor.movePosition(QtGui.QTextCursor.End, QtGui.QTextCursor.MoveAnchor)

        self.setTextCursor(cursor)

if __name__ == "__main__":
    import sys

    app = QtGui.QApplication(sys.argv)
    app.setApplicationName('MyWindow')

    main = MyWindow()
    main.show()

    sys.exit(app.exec_())