PDA

View Full Version : Issue with QTextCursor, LineUnderCursor and a very long line



kuku83
17th September 2012, 17:30
I am trying to insert a long text (about 100 words), content in a xml section, inside a QTextEdit with HTML rich text.

Example

<text> Lorem ipsum ad his scripta blandit partiendo, eum fastidii accumsan euripidis in, eum liber hendrerit an. Qui ut wisi vocibus suscipiantur, quo dicit ridens inciderint id. Quo mundi lobortis reformidans eu, legimus senserit definiebas an eos. </text>

When I insert the text it appers properly in the QTextEdit wrapped in 5 lines with widgetWidth wrapping, like this.

Lorem ipsum ad his scripta blandit partiendo, eum fastidii
accumsan euripidis in,eum liber hendrerit an. Qui ut wisi
vocibus suscipiantur, quo dicit ridens inciderint id. Quo
mundi lobortis reformidans eu, legimus senserit definiebas
an eos.

The problem appers when I try to get the first line with a QTextCursor::LineUnderCursor, it returns me like selectedText all the text (not the first line).

Any idea?

Thanks in advance

K

pkj
17th September 2012, 20:27
Welcome to the headaches of QTextCursor. In your case it is one line only. You are seeing it in multiple lines because QTextEdit::lineWrapMode() is on. So it wrapping up the text. But it still is only one line.

kuku83
18th September 2012, 10:40
yes, but i need to return the content line by line, is there any way to detect the line wrapping with QTextCursor?

pkj
18th September 2012, 10:55
Try QTextCursor::block()::text()

kuku83
19th September 2012, 11:15
Thanks for your reply, it returns the content of the block text, that is the full text, not the first line :-(

kuku83
7th November 2012, 17:59
I was trying this month with a lot of options, never good result, any suggestion?