PDA

View Full Version : How to limit the size of QLineEdit?



MIH1406
30th September 2009, 08:07
Hi,

I want to limit the size of QLineEdit to only 3 chars, how to do that?

Notice that the user can change the font of QLineEdit so I need it to resize to show only 3 chars in user selected font size?

Thanks,
Mohammad

yogeshgokul
30th September 2009, 08:25
Use:

QLineEdit::setMaxLength(3);

wysota
30th September 2009, 10:28
I want to limit the size of QLineEdit to only 3 chars, how to do that?

Reimplement sizeHint().

MIH1406
30th September 2009, 12:23
yogeshgokul:
setMaxLength() // Does not change the width of the QLineEdit

wysota:
What can I do with sizeHint()?

Thanks,
MIH1406

wysota
30th September 2009, 12:43
wysota:
What can I do with sizeHint()?

Whatever you want. Look at the sourcecode for QLineEdit::sizeHint() and in the subclass adjust it accordingly.

NoRulez
30th September 2009, 12:51
Or read the documentation (http://doc.trolltech.com/4.5/qlineedit.html#sizeHint).

Best Regards
NoRulez

yogeshgokul
30th September 2009, 13:10
Or read the documentation (http://doc.trolltech.com/4.5/qlineedit.html#sizeHint).
Only one line documentation ;)