QTextEdit *textEdit = new QTextEdit(this); QTextCursor cursor = textEdit->textCursor(); QString selectedText = cursor.selectedText();
QTextBrowser *textBrowser = new QTextBrowser(this); QTextCursor cursor = textBrowser->textCursor(); cursor.select(QTextCursor::WordUnderCursor); QString selectedText = cursor.selectedText();In this example, a QTextBrowser widget is created and the textCursor method returns a QTextCursor object for manipulating the text. The select method is then called on the QTextCursor object to select the word under the cursor. The selectedText method is then called on the QTextCursor object to retrieve the selected word. Package/Library: Qt