Results 1 to 4 of 4

Thread: Set Maximum Length of QTextEdit

  1. #1
    Join Date
    Mar 2010
    Posts
    63
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Set Maximum Length of QTextEdit

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Set Maximum Length of QTextEdit

    Qt Code:
    1. When text in text edit changed
    2. if text length is less than or equal to the maximum length
    3. do nothing <--- REALLY important! Otherwise you might end in an infinite loop
    4. else
    5. Truncate the text to the maximum length <--- this will fire the textChanged signal again!
    To copy to clipboard, switch view to plain text mode 

    You will be looking at textChanged(), toPlainText(), truncate(), setPlainText() and size() or length()
    Last edited by tbscope; 1st July 2010 at 15:18.

  3. #3
    Join Date
    Mar 2010
    Posts
    63
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Set Maximum Length of QTextEdit

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Set Maximum Length of QTextEdit

    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

Similar Threads

  1. QTextEdit - how to limit maximum length?
    By Henrikas[MI] in forum Qt Programming
    Replies: 7
    Last Post: 21st September 2010, 20:38
  2. Replies: 33
    Last Post: 10th June 2010, 16:51
  3. Maximum input length for QTextEdit or QPlainTextEdit ??
    By b_ginner in forum Qt Programming
    Replies: 2
    Last Post: 22nd August 2009, 20:57
  4. qt4 & xp - QTextEdit length
    By incapacitant in forum Newbie
    Replies: 4
    Last Post: 6th March 2006, 15:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.