Giorgi
Giorgi

Reputation: 179

How to change selected text in Qt?

How can we store in QString only selected text, which is typed in QTextEdit and change it (for example toUpper()) and change selected by it in QTextEdit?

Upvotes: 0

Views: 1695

Answers (1)

m.s.
m.s.

Reputation: 16334

This can be done through the QTextCursor API:

QTextCursor cursor = textEdit->textCursor();
if(cursor.hasSelection())
{
    cursor.insertText(cursor.selectedText().toUpper());
}

Upvotes: 3

Related Questions