How to take keyboard input from Right to Left in a QLineEdit in Pyside?



  • 0 down vote favorite

    I saw something that has the following code

    .QKeyEvent e(QEvent::KeyPress, Qt::Key_Direction_R, 0);

    QApplication::sendEvent(this, &e);

    I believe this is C++ code and I only vaguely understand what it is actually doing, some things in the Qt library I can do but a great deal of it leaves me scratching my head the I cannot 'translate' it properly, secondary question, could it be that I don't know how to read the Qt library properly ?



  • I don't know if I have understood this correctly but try this .-
    @
    lineEdit = QtGui.QLineEdit()
    lineEdit.setAlignment(QtCore.Qt.AlignRight)
    @

    HTH



  • this only aligns the cursor to the right of the QLineEdit()
    which I have already done, however when input is entered it is pushed from left to right, whereas it should make the cursor move over one place to the left ..hope this makes sense



  • Sorry I don't understand, you might want to say this. -
    @
    ...
    self.lineEdit = QtGui.QLineEdit()
    self.lineEdit.setAlignment(QtCore.Qt.AlignRight)
    self.lineEdit.textChanged.connect(self.foo)
    ...

    def foo(self):
    self.lineEdit.cursorBackward(False)
    @

    HTH



  • Tried it and it just keeps replacing the input in place



  • The same solution but without using classes, using python lambda function.
    This, to writing hello presents " |olleh" and the cursor is moves to left.
    @
    lineEdit = QtGui.QLineEdit()
    lineEdit.setAlignment(QtCore.Qt.AlignRight)
    lineEdit.textChanged.connect(
    lambda: lineEdit.cursorBackward(False))
    @

    HTH



  • Ok this last one worked perfectly .. Thank you much

    lineEdit = QtGui.QLineEdit()
    lineEdit.setAlignment(QtCore.Qt.AlignRight)
    lineEdit.textChanged.connect(
        lambda: lineEdit.cursorBackward(False))
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.