Results 1 to 5 of 5

Thread: QTextCursor select part of a word?

  1. #1
    Join Date
    Nov 2006
    Posts
    86
    Thanks
    6
    Thanked 14 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QTextCursor select part of a word?

    Ok, I can't figure this out from the Qt documentation, it just isn;t clear to me. If I have this text:
    asdf

    and the QTextCursor is positioned between the 's' and the 'd', how can I select "df"? I don't see any way of selecting one character at a time. Selection modes are:

    entire document
    block of text under cursor (which I read to be paragraphs)
    line under text cursor

    ...um so how do I do this?
    Paul

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextCursor select part of a word?

    This should do the trick:
    Qt Code:
    1. cursor.movePosition( QTextCursor::NextCharacter, QTextCursor::KeepAnchor, 2 );
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Nov 2006
    Posts
    86
    Thanks
    6
    Thanked 14 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTextCursor select part of a word?

    Well, that will let me move the QTextCursor one character at a time, but how do I select characters like that? I don't see anything like setSelectionStart()

    Paul

  4. #4
    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 select part of a word?

    Quote Originally Posted by thomaspu View Post
    Well, that will let me move the QTextCursor one character at a time, but how do I select characters like that? I don't see anything like setSelectionStart()
    Just like Jacek proposed. Quoting QTextCursor::movePosition() docs:
    If mode is KeepAnchor, the cursor selects the text it moves over. This is the same effect that the user achieves when they hold down the Shift key and move the cursor with the cursor keys.
    J-P Nurmi

  5. #5
    Join Date
    Nov 2006
    Posts
    86
    Thanks
    6
    Thanked 14 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTextCursor select part of a word?

    Ah, ok. Thats what I missed

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.