PDA

View Full Version : QplainTextEdit



deeee
26th May 2010, 16:54
hello,

how can I implement a function that will bring my cursor to a specific line number in a QPlainTextEdit window ?

Thanks.

tbscope
26th May 2010, 17:09
http://doc.qt.nokia.com/4.6/qplaintextedit.html#setTextCursor

Really, read the documentation!

deeee
26th May 2010, 17:26
ok thanks I actually saw this function but I was unsure this was the one I needed.
How can I use it ?
I don't really know what QTextCursor is, nor how to initialize it so that I could go to the line number I want.

jryannel
26th May 2010, 17:28
For my knowledge you are looking for blocks (e.g. a text paragraph) http://doc.qt.nokia.com/4.6/richtext-structure.html#text-blocks and look for http://doc.qt.nokia.com/4.6/qtextdocument.html#findBlockByLineNumber.

A QTextCursor accepts a QTextBlock during construction.

tbscope
26th May 2010, 17:34
A line ends with a carriage and linefeed. Count them. Use the position of the crlf combo + 2 to set your text cursor.
Edit: or what jryannel says

deeee
26th May 2010, 18:30
okay, so I tried this :
void QPlainTextEdit::gotoLine(int n)
{
QTextCursor* test = new QTextCursor (this->findBlockByLineNumber(n));
this->setTextCursor(test);
}

it seems I'm wrong.
Can you help me to make it right ?
Thanks

deeee
27th May 2010, 00:14
This gives a compilation error, these functions can't be used with these classes, but I don't know how else to make it work.
Can you help me please ?