PDA

View Full Version : QPlainText Edit and text lines



aarelovich
23rd June 2010, 00:27
Hello:

I was wondering if there is any way to make the cursor go to specific line number of a text written in QPlainTextEdit.

Thank you for any answers.

high_flyer
23rd June 2010, 10:27
pQPlainTextEdit->textCursor->setPos().

A line number can be deduced from the number of new lines ('\n')

JohannesMunk
23rd June 2010, 10:50
Linenumber: as in with our without taking the line wrapping into account?

Without:


int pos = plaintextedit->document()->findBlockByNumber(yourparagraphnumber).position();

To set the cursor there:


QTextCursor cur = plaintextedit->textCursor();
cur.setPosition(pos);
plaintextedit->setTextCursor(cur);


Johannes

aarelovich
23rd June 2010, 14:02
Yes that was exactly what I wanted!

Thank you.

The thing is that I had found the findBlockbyNumber (or LineNumber, too) but I had not found the .position() property of the block to turn it into an integer with which to set the textCursor.

Thank you again!

JohannesMunk
23rd June 2010, 14:09
You are welcome! No need to say thanks twice, though :-> Just use the forums thank button!

Happy coding!

Johannes