LR-27
LR-27

Reputation: 3

How to select a character in QTextEdit

I want to select a single character in a QTextEdit widget and then change it's format. But I found that select() funciton only support 4 types: Document, BlockUnderCursor, LineUnderCursor and WordUnderCursor.

So, is there any other way can only select a char?

Thanks!

Upvotes: 0

Views: 1304

Answers (1)

Viv
Viv

Reputation: 17380

You can use QTextCursor for this

Assuming you know the position of the character you want to select as (charPosition)

QTextCursor cursor = ui_->textEdit->textCursor();
cursor.setPosition(charPosition);
cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
ui_->textEdit->setTextCursor(cursor);

Upvotes: 3

Related Questions