Results 1 to 2 of 2

Thread: QTextEdit and cursor

  1. #1
    Join Date
    Jul 2008
    Qt products

    Default QTextEdit and cursor

    I have QTextEdit "textbox".
    I want to do this:
    Somebody is writing something in this QTextEdit "textbox". next he is clicking button, program is taking line by line text from QTextEdit and program throwing line by line to the list text which somebody have written , next program is sorting lines of text and program is showing sorted lines of text in QTextEdit.

    I made it that:
    Qt Code:
    1. QString line;
    3. QTextCursor cursor(textbox->textCursor());
    5. cursor.movePosition(QTextCursor::End);
    6. int end = cursor.position();
    8. cursor.movePosition(QTextCursor::Start);
    9. int start = cursor.position();
    13. for(int i=start; i<end; i=cursor.position())
    14. {
    15. line=........ ? // <- I must take here present line of text
    16. list.push_back(line);
    17. cursor.movePosition(QTextCursor::Down);
    18. cursor.movePosition(QTextCursor::StartOfLine);
    19. }
    To copy to clipboard, switch view to plain text mode 

    Is it ok ? It is something new for me. How can I take all present line of text to throw it to the list ?

  2. #2
    Join Date
    Jan 2006
    Warsaw, Poland
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Unix/X11 Windows

    Default Re: QTextEdit and cursor

    You can get the text through QTextCursor::selectedText(), but first you have to select it. You do that by calling movePosition() with QTextCursor::KeepAnchor as the second parameter.

Similar Threads

  1. [Qt4] QTextEdit & cursor visibility
    By Ti_Thom in forum Qt Programming
    Replies: 5
    Last Post: 27th September 2012, 06:04
  2. Trouble with cursor and selecting text in QTextEdit
    By R_Torsten in forum Qt Programming
    Replies: 3
    Last Post: 7th June 2008, 19:17
  3. How to synchronize text cursor and cursor in QTextEdit
    By kennyxing in forum Qt Programming
    Replies: 6
    Last Post: 18th February 2007, 09:14
  4. QTextEdit: I can not see the cursor by deafult
    By sukanyarn in forum Qt Programming
    Replies: 1
    Last Post: 10th October 2006, 07:55
  5. a question about visualizing cursor in read-only QTextEdit
    By kennyxing in forum Qt Programming
    Replies: 3
    Last Post: 17th September 2006, 19:52


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.