Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. How to take keyboard input from Right to Left in a QLineEdit in Pyside?

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

Scheduled Pinned Locked Moved Language Bindings
7 Posts 2 Posters 3.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hjrios.c
    wrote on last edited by
    #1

    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 ?

    1 Reply Last reply
    0
    • X Offline
      X Offline
      xavi
      wrote on last edited by
      #2

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

      HTH

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hjrios.c
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • X Offline
          X Offline
          xavi
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • H Offline
            H Offline
            hjrios.c
            wrote on last edited by
            #5

            Tried it and it just keeps replacing the input in place

            1 Reply Last reply
            0
            • X Offline
              X Offline
              xavi
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • H Offline
                H Offline
                hjrios.c
                wrote on last edited by
                #7

                Ok this last one worked perfectly .. Thank you much

                lineEdit = QtGui.QLineEdit()
                lineEdit.setAlignment(QtCore.Qt.AlignRight)
                lineEdit.textChanged.connect(
                    lambda: lineEdit.cursorBackward(False))
                
                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved