PDA

View Full Version : input mask problem



zgulser
6th May 2009, 10:08
Hi,

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

zgulser
7th May 2009, 07:10
Hi again,

Let me clarify the question a little more

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

myLineEdit->setText(QString::number(10));

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.

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

zgulser
7th May 2009, 10: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!

wysota
7th May 2009, 11: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;
le.setInputMask("99:99");
le.setText(QString::number(10));
le.show();
return app.exec();
}

zgulser
7th May 2009, 12:14
4.4.2

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

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

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

Thanks for your replies.

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

zgulser
8th May 2009, 13:55
Hi,

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?

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