[Qt-interest] Implement a Go to line

David Villalobos Cambronero david.villalobos.c at gmail.com
Tue Apr 19 02:42:12 CEST 2011


It does no work, the current line does not change. I use this code.

void Editor::gotoline(int lineNumber)
{
  QTextCursor *cursor = new QTextCursor(textEditor->textCursor());
  cursor->movePosition(QTextCursor::PreviousBlock, QTextCursor::MoveAnchor,
lineNumber);
//  cursor.setPosition(lineNumber);
}

void Editor::itemClickedSlot(QListWidgetItem *item)
{
  gotoline((int)(symbolsLineNumber.value(item->text())));
}



Regards
---
David


On Mon, Apr 18, 2011 at 17:11, John Weeks <john at wavemetrics.com> wrote:

>
> 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/b03e029e/attachment.html 


More information about the Qt-interest-old mailing list