Reputation: 3
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
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