PDA

View Full Version : QTextCursor select part of a word?



thomaspu
12th February 2008, 22:06
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

jacek
12th February 2008, 23:21
This should do the trick:
cursor.movePosition( QTextCursor::NextCharacter, QTextCursor::KeepAnchor, 2 );

thomaspu
12th February 2008, 23:49
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

jpn
13th February 2008, 09:28
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.

thomaspu
13th February 2008, 18:01
Ah, ok. Thats what I missed