Results 1 to 4 of 4

Thread: linebreaks in a textblock

  1. #1
    Join Date
    Jul 2012
    Posts
    248
    Thanks
    29
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default linebreaks in a textblock

    I need to format and manage text in a QTextEdit. The text "items" are usually one line long, such as


    Nr1233 Munich abcd
    However, sometimes they are several lines long, such as

    Nr1234 Munich some lengthy comment \n some more \n and more
    this messes up my text managing, since i work over QTextBlocks. And every line break generates a new TextBlock.

    I tried to wrap all my items in QTextFrames, but that generates unwanted linebreaks itself (ie the QTextFrame generates a linebreak automatically).

    Qt Code:
    1. for(...)
    2. {
    3. QTextCursor tc = txtedit->document()->rootFrame()->lastCursorPosition();
    4. tc.insertFrame(QTextFrameFormat());
    5. tc.insertText("testline");
    6. }
    To copy to clipboard, switch view to plain text mode 

    will output:


    Qt Code:
    1. testline
    2.  
    3. testline
    4.  
    5. testline
    6.  
    7. testline
    To copy to clipboard, switch view to plain text mode 


    How can i have a textblock that spans several lines? Or: how can i not have automatic linebreaks after the qtextframe?


    Observation: if my textblock is very long, but doesnt contain any linebreaks, it is wrapped automatically and all works well. The problme occurs when i try to process linebreaks that are in the string itself.
    Last edited by tuli; 27th July 2014 at 08:47.

  2. #2
    Join Date
    Jul 2014
    Posts
    6
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: linebreaks in a textblock

    Try "Nr1234 Munich some lengthy comment <br />some more <br />and more". TextEdit supports HTML

    Wishes.
    Afa.L Cheng

  3. #3
    Join Date
    Feb 2006
    Location
    Jarrell, Texas, USA
    Posts
    70
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: linebreaks in a textblock

    Can you put your textblock outside the loop and only have insertText calls within the loop?

    Karl

  4. #4
    Join Date
    Jul 2012
    Posts
    248
    Thanks
    29
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: linebreaks in a textblock

    you mean by QTextCursor?

    yes i can, but i dont think it changes anything.

Similar Threads

  1. How to set TextFormat of a TextBlock directly
    By wang9658 in forum Qt Programming
    Replies: 4
    Last Post: 23rd May 2012, 15:06
  2. a Readonly Highlighted TextBlock in QTextEdit?
    By vertusd in forum Qt Programming
    Replies: 3
    Last Post: 21st July 2010, 15:50
  3. setVisible textblock in QTextEdit
    By corrado in forum Qt Programming
    Replies: 2
    Last Post: 27th April 2010, 03:04
  4. linebreaks QGraphicsTextItem
    By nicolas1 in forum Qt Programming
    Replies: 2
    Last Post: 28th November 2008, 10:27

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.