Help Changing Format of TextEdit Without Replacing Contents
Unsolved
General and Desktop
-
For some reason, I can't use "toPlainText()" and "toHtml()" as the arguments for "setPlainText()" and "setHtml()."
I'm able to get toPlainText() and toHtml() in the console just fine, but it just doesn't convert.
void TextFinder::on_checkBox_clicked() { qDebug() << "on_checkBox_clicked() called"; // Check if the checkbox is checked if (ui_checkBox->isChecked()) { // Set the textEdit to plain text ui_textEdit->setPlainText(ui_textEdit->toPlainText()); } else { // Set the textEdit to HTML format ui_textEdit->setHtml(ui_textEdit->toHtml()); } }
I even tried this:
void TextFinder::on_checkBox_clicked() { qDebug() << "on_checkBox_clicked() called"; // Retrieve the current content of the textEdit QString currentText = ui_textEdit->toPlainText(); if (ui_checkBox->isChecked()) { // Convert plain text to HTML by wrapping it with basic HTML tags QString htmlText = "<html><body><p>" + currentText.toHtmlEscaped().replace("\n", "<br>") + "</p></body></html>"; ui_textEdit->setHtml(htmlText); } else { // Set the textEdit back to plain text ui_textEdit->setPlainText(currentText); } }
but nothing changed.
-
@CodermanBill wrote, "but nothing changed".
You take some plain text, wrap it in HTML that does not attempt to style or otherwise format it, reinsert it into the editor, and expect something to change (I assume visually). What exactly are you expecting?