Results 1 to 3 of 3

Thread: QTextCursor::selectedText

  1. #1
    Join Date
    Mar 2006
    Posts
    48
    Thanks
    5
    Thanked 4 Times in 3 Posts

    Question QTextCursor::selectedText

    i have this code
    Qt Code:
    1. TextEdit::TextEdit()
    2. {
    3. setPlainText("text1\ntext2");
    4. select();
    5. }
    6. //
    7. void TextEdit::select()
    8. {
    9. QTextCursor cursor = textCursor();
    10. while (!cursor.atEnd())
    11. {
    12. cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);
    13. }
    14. cout <<qPrintable(cursor.selectedText())<<endl;
    15. }
    To copy to clipboard, switch view to plain text mode 

    so my text is "text1\ntext2" but function select() return "text1?text2"
    '?' it's unprintable Enter?
    how to get text in normal mode with '\n' using QTextCursor?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTextCursor::selectedText

    QTextCursor::selectedText():
    Note: If the selection obtained from an editor spans a line break, the text will contain a Unicode U+2029 paragraph separator character instead of a newline \n character. Use QString::replace() to replace these characters with newlines.
    PS. Why not use QTextEdit::selectAll()?
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    evgenM (8th November 2007)

  4. #3
    Join Date
    Mar 2006
    Posts
    48
    Thanks
    5
    Thanked 4 Times in 3 Posts

    Default Re: QTextCursor::selectedText

    thanks
    it's just example - i don't need select all text

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.