Results 1 to 4 of 4

Thread: Trouble with cursor and selecting text in QTextEdit

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Trouble with cursor and selecting text in QTextEdit

    Thx, but i know it.
    I want to select text and dont move cursor position.

    Just trying select text, for example all current line and dont move cursor position.
    I trying.

    Qt Code:
    1. QTextCursor cursor = textCursor();
    2. cursor.setPosition(nStartSelectionPos);
    3. cursor.setPosition(nEndSelectionPos, QTextCursor::moveAnchor);
    4. setTextCursor(cursor);
    To copy to clipboard, switch view to plain text mode 

    Yeah and cursor was stayed in end of selection text.
    If do it, like this :
    Qt Code:
    1. QTextCursor cursor = textCursor();
    2. int nCurPos = cursor.position();
    3. cursor.setPosition(nStartSelectionPos);
    4. cursor.setPosition(nEndSelectionPos, QTextCursor::moveAnchor);
    5. cursor.setPosition(nCurPos);
    6. setTextCursor(cursor);
    To copy to clipboard, switch view to plain text mode 
    No selected text, because cursor is moving - its my problem.

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    6
    Thanked 163 Times in 151 Posts

    Default Re: Trouble with cursor and selecting text in QTextEdit

    Try creating a cursur like that
    QTextCursor c(document);

    where document is your QTextDocument*


    If that makes no difference:
    call position() on the cursor before doing the selection, and restore (only) the position when you're done with setPosition.



    Not sure if it will work, but worth a try.

    Good luck!

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
  •  
Qt is a trademark of The Qt Company.