[Qt-interest] Implement a Go to line
John Weeks
john at wavemetrics.com
Tue Apr 19 01:11:26 CEST 2011
On Apr 18, 2011, at 3:38 PM, David Villalobos Cambronero wrote:
> I have a QPlainTextEdit and I want to implement a Go To Line function, I've try to look in the source if qtcreator, but couldn't find any clue.
>
> Any idea of how to implement it?
QPlainTextEdit * edit = ...
QTextCursor cursor = edit->textCursor();
int linenumber = cursor->blockNumber();
int linedif = goto - linenumber;
if (linedif < 0)
cursor->movePosition(QTextCursor::PreviousBlock, QTextCursor::MoveAnchor, -linedif);
else
cursor->movePosition(QTextCursor::NextBlock, QTextCursor::MoveAnchor, linedif);
That's uncompile pseudo-code :)
Seems complicated, eh? That's how I figured out to do it. Maybe there's some shortcut...
Regards, John Weeks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110418/573ad297/attachment.html
More information about the Qt-interest-old
mailing list