Results 1 to 5 of 5

Thread: Hide/unhide paragraphs in QTextEdit

  1. #1
    Join Date
    Jan 2006
    Posts
    31
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanked 5 Times in 4 Posts

    Default Hide/unhide paragraphs in QTextEdit

    Hi,

    I have some text to display in a QTextEdit and I would like to hide/unhide some parts on a toggle command.

    Currently I use QSyntaxHighlighter to color some selected parts, I would like to know if there is a way to also hide that parts.

    I have tried to setting font to 1 pixel size and also setting color to QTextEdit background but with no good results because, also if invisible the hidden part takes (empty) space so you still see an empty 'gap' in the text.

    There is a way to achieve that?

    Thanks
    Marco

  2. #2
    Join Date
    Jan 2007
    Posts
    209
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Hide/unhide paragraphs in QTextEdit

    Why not just figure out where in the text you want to delete, and use TextCursor to delete that specific part, save that part in some variable or whatever, and then when you want to add it again, paste it again at the saved spot?

  3. #3
    Join Date
    Jan 2006
    Posts
    31
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanked 5 Times in 4 Posts

    Default Re: Hide/unhide paragraphs in QTextEdit

    I would like to hide/unhide some parts of the text so that if I use two QString variables one for original text and one for shrinked text I have the problem to restore the screen at the right content, as example if I am at line 200 and hide the first 30 lines I would like still be at visible line 200 - 30 = 170 so that user does not see content scrolling artifact when hiding/unhiding.

    To do this I hoped to find a supported way in QTextEdit because save and restore the contents positions is not easy (expecially in Qt4) and in any case I would need a map that says that line 200 of original content corresponds to line 170 of shrinked one and to do this for each line.

    So a native way should be far better ;-)

  4. #4
    Join Date
    Jan 2007
    Posts
    209
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Hide/unhide paragraphs in QTextEdit

    Well obviously there is no hide unhide in QTextEdit, so you will have to just delete and repaste ... to imitate that.

  5. #5
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 127 Times in 121 Posts

    Default Re: Hide/unhide paragraphs in QTextEdit

    Quote Originally Posted by VireX View Post
    Well obviously there is no hide unhide in QTextEdit, so you will have to just delete and repaste ... to imitate that.
    Deleting is OK as long as you keep what you delete somewhere... One simple way is probably to use a custom structure passed to QTextBlock::setUserData() which will store the temporarily hidden text in the way you like. This is especially interesting when what you call hide/unhide is actually "text folding" in this case the main drawback of this method becomes an advantage because the hidden data gets automatically deleted when corresponding blocks are removed. If you want some inspiration on how to do this you may consider having a look at QCodeEdit which provides such text folding.
    Last edited by fullmetalcoder; 16th April 2007 at 11:04. Reason: spelling error
    Current Qt projects : QCodeEdit, RotiDeCode

Similar Threads

  1. Re-implement mouse events of QTextEdit
    By Ankitha Varsha in forum Qt Programming
    Replies: 2
    Last Post: 14th October 2006, 16:55
  2. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03
  3. [QT 4] QTextEdit performance
    By fellobo in forum Qt Programming
    Replies: 8
    Last Post: 6th March 2006, 19:27
  4. Painting to QTextEdit
    By gesslar in forum Qt Programming
    Replies: 8
    Last Post: 18th February 2006, 18:40
  5. Obtaining clean (x)html from QTextEdit
    By ccf_h in forum Qt Programming
    Replies: 1
    Last Post: 5th February 2006, 14:47

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
  •  
Qt is a trademark of The Qt Company.