Is there a way to get the SELECTED text from a QTextEdit? (i.e. selected by the user in the GUI?).
The QTextCursor seems unfruitful -- when creating one on the QTextEdit's QTextDocument -- either before or after the selection -- its anchor and position -- don't contain results from user selections.
I'm currently "PUSHING" the QTextEdit through the system clipboard via QTextEdit::copy(), see below. I hate nailing the system clipboard for this purpose. There must be a better way.
[This is with Qt 4.6.3 on Windows and Solaris].
... ... ...
// We have to "push" the user-selected text to the conventional
// system clipboard (using the QClipboard::Clipboard clipboard mode).
// Clear first, because the QTextEdit::copy() command doesn't do this
// if nothing is selected.
msgBox->copy();
QTextEdit* msgBox = new QTextEdit (this);
... ... ...
// We have to "push" the user-selected text to the conventional
// system clipboard (using the QClipboard::Clipboard clipboard mode).
// Clear first, because the QTextEdit::copy() command doesn't do this
// if nothing is selected.
QApplication::clipboard()->clear (QClipboard::Clipboard);
msgBox->copy();
const QString clipSel2 =
QApplication::clipboard()->text (QClipboard::Clipboard);
To copy to clipboard, switch view to plain text mode
Bookmarks