PDA

View Full Version : linebreaks in a textblock



tuli
27th July 2014, 08:43
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).



for(...)
{
QTextCursor tc = txtedit->document()->rootFrame()->lastCursorPosition();
tc.insertFrame(QTextFrameFormat());
tc.insertText("testline");
}

will output:





testline

testline

testline

testline




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.

hmasterwang
27th July 2014, 18:42
Try "Nr1234 Munich some lengthy comment <br />some more <br />and more". TextEdit supports HTML

KaptainKarl
29th July 2014, 22:47
Can you put your textblock outside the loop and only have insertText calls within the loop?

Karl

tuli
3rd August 2014, 15:01
you mean by QTextCursor?

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