I created a QLineEdit lineEdit_X_Position input in PyQt4.
I have created a input mask with self.ui.lineEdit_X_Position.setInputMask(“00,000.00;_”).
I set the lineEdit with default value self.ui.lineEdit_X_Position.setText( format(‘6543.21’, “,.2f”) ).
When I view the UI, it shows X_Position as “6_,543.21” instead of “_6,543.21”.
I tried to set the default with self.ui.lineEdit_X_Position.setText( format(‘6543.21’, “9.2f”) ), but results = “65,43_.21”.
It gets worst when the default value is “543.21”. I get results as “54,3__.21”.
Is this a bug in QInputMask?
How to get the correct result with the QInputMask format that I want, where user can only enter numbers?
Also, if I want to validate the double results, how to use the QDoubleValidator?
The valid range is 0.00 to 10,000.00.
There is no bug in
QInpuMask.The mask you set allows certain values to be entered in a number of different ways – all of which are equally valid. For instance, the value “543.2” could be entered by a user as
5_,_4_3._2or__,543.2_, or_5,4__3._2, etc.When such a value is entered programmatically, Qt cannot guess which of the the various possiblities is the “preferred” one, and just fills in the blanks in the direction they would normally be typed. So the output you are seeing is correct, and exactly as expected.
But given that you are trying to limit values to numbers in a certain range rather than characters in a fixed pattern, is an input mask really the right choice?
A
QDoubleSpinBoxwould seem to be a much better fit: