QTextEdit - how to capture the actual "selection changed " text ?
-
Am I using wrong widget ?
I am using "system" call to fill QTextEdit.
Then I need to select and process specific text.
Putting a mouse on ANY part of the desired text generates
"selection changed" signal, works fine...How do I retrieve the actual text ?
-
Am I using wrong widget ?
I am using "system" call to fill QTextEdit.
Then I need to select and process specific text.
Putting a mouse on ANY part of the desired text generates
"selection changed" signal, works fine...How do I retrieve the actual text ?
@AnneRanch
The whole of the text is available throughtextEdit->toPlainText()
.
The selected text is available throughtextEdit->textCursor().selectedText()
ortextEdit->textCursor().selection().toPlainText()
.Separately.
Presumably you had to write or find some code to capture the output from asystem()
call to get it into aQTextEdit
. And it involved doing something withstdout
. The Qt way of doing this can be reduced to (no error checking):QProcess process; process.start("/bin/ls", QStringList() << "-la"); // example for: system("/bin/ls -la") process.waitForFinished(); textEdit->setPlainText(process.readAllStandardOutput());
-
This does not work - no data retrieved.
QString textSelection = ui->textEdit_6->textCursor().selectedText();This works fine , BUT I do not need ALL text, just selected one.
textSelection = ui->textEdit_6->toPlainText();
-
This does not work - no data retrieved.
QString textSelection = ui->textEdit_6->textCursor().selectedText();This works fine , BUT I do not need ALL text, just selected one.
textSelection = ui->textEdit_6->toPlainText();
@AnneRanch said in QTextEdit - how to capture the actual "selection changed " text ?:
QString textSelection = ui->textEdit_6->textCursor().selectedText();
It should do, assuming text has been selected there, like dragging the mouse over it so that you see the selected text highlighted. You can try the alternative
ui->textEdit_6->textCursor().selection().toPlainText()
though it should return the same result. -
@AnneRanch said in QTextEdit - how to capture the actual "selection changed " text ?:
QString textSelection = ui->textEdit_6->textCursor().selectedText();
It should do, assuming text has been selected there, like dragging the mouse over it so that you see the selected text highlighted. You can try the alternative
ui->textEdit_6->textCursor().selection().toPlainText()
though it should return the same result.@JonB I still think I am using wrong widget / signal. I can only position and click the mouse. I cannot highlight the text - the positioning of mouse overrides that.