raze
raze

Reputation: 702

Qt: create custom QTextCursor select

So, the method select(SelectionType) in the class QTextCursor only has 4 possible parameters.

QTextCursor::Document
QTextCursor::BlockUnderCursor
QTextCursor::LineUnderCursor
QTextCursor::WordUnderCursor

Is it possible to create custom selectiontypes? Say if I want to select the text from position 5 to 9. Thanks!

http://doc.qt.io/qt-5/qtextcursor.html#select

Upvotes: 0

Views: 1115

Answers (1)

king_nak
king_nak

Reputation: 11513

Use setPosition like this:

cursor.setPosition(5);
cursor.setPosition(9, QTextCursor::KeepAnchor);

This will set the cursor's Anchor to 5 and its Position to 9. The selection is the text between anchor and position.

Upvotes: 3

Related Questions