PDA

View Full Version : Carriage return line feed - in qtextedit do not display text properly



rdjenner
26th March 2011, 22:43
I have a window with a qtextedit that I use for notes. 2 problems I am having. First is that the text being display from the db does not format to the carriage retrun and line feeds, it all appears as one lone string. I can display this same data in crystal report and the data is formatted correctly. 2nd issue is that when I update this text, it then appears to wipe out my carriage return line feeds. I am importing these note via mysql using a concat(note1, '\n', note2). Any idea's

wysota
27th March 2011, 19:19
What if you concat \r\n instead of \n?

rdjenner
27th March 2011, 23:13
I tried that with the same results.

SixDegrees
27th March 2011, 23:18
What is QTextEdit.lineWrapMode set to?

wysota
27th March 2011, 23:18
Why are you performing the concatenation?

rdjenner
28th March 2011, 18:46
It is set to Word wrap which work ok.

SixDegrees
28th March 2011, 20:51
It is set to Word wrap which work ok.

Then I'm confused. This doesn't sound like a "one long string" problem anymore; it sounds more like you're expecting some sort of paragraph formatting - like a blank line insertion - following each CRLF.

If line wrapping is working, what exactly is the problem?

rdjenner
28th March 2011, 22:10
I use concat because the old notes table had multiple lines for a order. Table structure was order, seq, note and for each new line of the note it would increase the seq. In other words I could have seq 1-15 with each note for that seq representing a new note line. When the notes print out, the need to display in that order. During the conversion I created a new table which was just order, note (varchar 4000) and when I import the old notes to the new I concat each seq of line notes with a \n to ensure the notes are displayed as seperate lines in my new text field. When I pull up these new notes in qtextedit, they appear as one long string, although when I pull these in crystal, they show up as new lines with the line feeds. When I edit the text in the qtextedit (add a new line) and redisplay it appears as one long string, although in crystal it appears correctly. If I go in and edit any portion of the text that was imported in, it appears to wipe out all line feeds because when I then pull up in crystal it appears as one huge string word wrap and ignores the previous line feeds.

wysota
28th March 2011, 22:33
Fetch each paragraph separately and join them into one string in your application. Either that or repair the concatenated string you get from the database. Apparently your MySQL runs on Unix so \n is a LF instead of CRLF Windows expects. Using \r\n in your query should have worked too.

SixDegrees
28th March 2011, 23:51
See QTextDocument, QTextBlock and QTextBlockFormat. These allow you to control the display of your text, including adding margins above/below paragraphs.