Pyside QLineEdit entering data from right-to-left



  • So, I have a somewhat unique data-entry need. It's not really unique, but I can't seem to find a way to implement it in PySide. Specifically, I have a field that is filled with a floating-point number. It takes the form of "00009+99.00"

    Because the first four leading values are optional, I'd rather data entry began at the right and was pushed to the left. That is, the cursor would remain fixed at right and as the user entered data, it would expand leftward. Is there a way to do that without trying to concoct a Python function that gets called when the text gets changed?


  • Qt Champions 2018

    @Joel-Graff your example does not look like valid float number.

    Do you need exponential format? I'm not sure, if QDoubleSpinbox provides that, otherwise it would be first choice for that task. For the line edit, you could use input masks or hook up an own 'correction function' on every key press.



  • @aha_1980 said in Pyside QLineEdit entering data from right-to-left:

    @Joel-Graff your example does not look like valid float number.
    Do you need exponential format? I'm not sure, if QDoubleSpinbox provides that, otherwise it would be first choice for that task. For the line edit, you could use input masks or hook up an own 'correction function' on every key press.

    It is, in fact, a valid float. It's called a "station" where 1 station = 100 feet. Thus 999 feet = 9.99 stations, which is commonly annotated 9+99. It's really just a length. The example I gave is actually the input mask I'm using - sorry for the confusion. The problem is, the input mask doesn't really fill out the required placeholders correctly. That is, if I create an input mask that reads:

    '00009+99.00;_'
    

    I would expect it to show

    ____0+00.__
    

    as a default. Of course, it doesn't, and I admit, I don't really know much about input masks in Qt.

    Since I can't rely on the input mask to control the data entry, forcing it to enter data from the right (and push the characters to the left) seems the next best option. It's a fairly common data entry technique - I've seen it even in very old terminal-based systems. I was hoping I didn't have to craft my own callback to manage it.

    Thanks anyway. :)


 

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