View Full Version : input mask problem

6th May 2009, 11:08

I have a lineedit which I put an input mask in it. The input mask is something like (99:99).
When I try to put some data in it, it doesn't show the data in the input mask format.(I guess it's normal!?). How to make my data visible like the input mask?

Thanks in advance

7th May 2009, 08:10
Hi again,

Let me clarify the question a little more

I want to put some data into the lineedit from somewhere like;


But as I told before, I have an input mask in my line edit(99:99) so I want my number 10 looks 10:00.

I wonder if I have anything to do with any QT's functions or classes to perform this operation. Or I should take care of it by myself.

7th May 2009, 10:28
What do you receive after the setText() call? Something like "10: "?

7th May 2009, 11:25
Nope mate, I when I put 10 for example, I get 16656 in the place of the lineedit.

But when I click on the lineedit, I mean when I give the focus, It becomes like 16:56

By the way my type is long for the number I put in the lineedit!

7th May 2009, 12:04
For me it works as expected... What version of Qt do you have?

#include <QtGui>

int main(int argc, char **argv){
QApplication app(argc, argv);
QLineEdit le;
return app.exec();

7th May 2009, 13:14

By the way what did you get exactly? 10:00?

7th May 2009, 13:19
"10: ", as expected.

7th May 2009, 15:20
I guess I'm missing some point.
Cuz it worked for me too.

Thanks for your replies.

7th May 2009, 15:32
If you want the zeroes to be appended automatically, change the input mask to: "99:99;0"

8th May 2009, 14:55

problem solved! thanks.

But I have another problem now. You know if the inputMask does not fit what you wrote in the lineedit, editingFinished() signal does not work. So when you focus out from the lineedit with the cursor and still the inputMask does not fit with the text in lineedit, although you lost the focus in that lineedit editingFinish() signal isn't emitted!

I wrote a method that takes the string in lineedit and make it fit with inputMask visually when the lineedit loses the focus by the cursor , but unfortunately I'am not able to emit edittingFinish() signal. Is there a way to perform this?

8th May 2009, 15:11
Apply a validator (subclass of QValidator) on the widget and make sure its fixup() method is implemented correctly. This should do the trick.