[Qt-interest] Implement a Go to line
John Weeks
john at wavemetrics.com
Tue Apr 19 18:41:54 CEST 2011
On Apr 18, 2011, at 5:42 PM, David Villalobos Cambronero wrote:
> 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())));
> }
As Ben said, don't create a new cursor, retrieve the cursor from the Text Edit widget. You can modify the text using a new cursor, but to change the display you need to use the cursor that's used by the widget.
And you'll need to implement the part of my code that computes the difference between the current position and the desired line and use that offset rather than the line number itself.
Regards, John Weeks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110419/65dbd89b/attachment.html
More information about the Qt-interest-old
mailing list