Results 1 to 2 of 2

Thread: Setting textCursor position with line and column

  1. #1
    Join Date
    Mar 2010
    Posts
    7
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Setting textCursor position with line and column

    Hello everybody,

    I'm trying to move the cursor of a QTextEdit to a position that is specified with line number and column. I've tried with movePosition() in the QTextCursor like this:

    Qt Code:
    1. QTextEdit * editor;
    2. //Moves the cursor to the beginning of the document
    3. editor->textCursor().setPosition(0,QTextCursor::MoveAnchor);
    4. //Now moves the cursor to the line "line" and in the column "index"
    5. editor->textCursor().movePosition(QTextCursor::Down, QTextCursor::MoveAnchor,line-1);
    6. editor->textCursor().movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, index);
    To copy to clipboard, switch view to plain text mode 

    However, the only thing I get with this is the cursor in the same position as the beginning.
    Does anybody know how to achieve this??

    Thank you in advance!

    Alberto

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Setting textCursor position with line and column

    Use QTextCursor::NextBlock to go to the next line and you have to work with a copy of the cursor which has to be reset to to editor:
    Qt Code:
    1. QTextCursor c = editor->textCursor();
    2. c.movePosition(/*...*/);
    3. editor->setCursor(c);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QStandardItem: Setting Top Column Data?
    By AaronMK in forum Qt Programming
    Replies: 2
    Last Post: 24th January 2008, 20:13
  2. Setting one* column of QTreeView to be editable
    By forrestfsu in forum Qt Programming
    Replies: 2
    Last Post: 18th October 2006, 20:31
  3. How to get column number in a line
    By showhand in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2006, 09:42
  4. Setting Delegates per Column
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 30th May 2006, 21:39
  5. How to restore the position of the textCursor?
    By Dark_Tower in forum Qt Programming
    Replies: 1
    Last Post: 25th April 2006, 19:41

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.