PDA

View Full Version : Set Maximum Length of QTextEdit



moh.gup@gmail.com
1st July 2010, 15:29
Hi,
I want to set maximum limit of input text in QtexEdit.It is done by typing or by patsing only 1000 charcters should allowed.
Please suggest

tbscope
1st July 2010, 16:13
When text in text edit changed
if text length is less than or equal to the maximum length
do nothing <--- REALLY important! Otherwise you might end in an infinite loop
else
Truncate the text to the maximum length <--- this will fire the textChanged signal again!

You will be looking at textChanged(), toPlainText(), truncate(), setPlainText() and size() or length()

moh.gup@gmail.com
2nd July 2010, 09:18
Thanks for response.
My Text is richedit.If I used toplaintext() and setplaintext() then my text property will lost.And with toHTML i am not able to truncate properly as they contail HTML tags
Please suggest

tbscope
2nd July 2010, 09:27
Your case is very specific.

You could use the plain text to check the length.
Then do something to find where to cut off the text.
Then use the html text and find that place in your html text and cut off the text.
Be carfull to close the tags too