How to get richtext from textedit?
-
bool DocHandler::save(const QString &name) { QString filename=curFile; if(!name.isEmpty()) filename=name; QFile file(filename); if(!file.open(QIODevice::WriteOnly)) { const QMessageBox::StandardButton ret = QMessageBox::warning(this, tr("MutiDoc"), tr("Canot write file %1;\n" "Erro: %2" ) .arg(file.fileName()).arg(file.errorString()) ); return false; } QDataStream out(&file); out.setVersion(QDataStream::Qt_5_7); QApplication::setOverrideCursor(Qt::WaitCursor); out<<this->toPlainText(); QApplication::restoreOverrideCursor(); setCurrentFile(filename); return true; }like this just can get plaintext even if i use QDataStream but QTextStream.I want to get richtext form textedit include color and other info.What can i do? Thank for your help
-
bool DocHandler::save(const QString &name) { QString filename=curFile; if(!name.isEmpty()) filename=name; QFile file(filename); if(!file.open(QIODevice::WriteOnly)) { const QMessageBox::StandardButton ret = QMessageBox::warning(this, tr("MutiDoc"), tr("Canot write file %1;\n" "Erro: %2" ) .arg(file.fileName()).arg(file.errorString()) ); return false; } QDataStream out(&file); out.setVersion(QDataStream::Qt_5_7); QApplication::setOverrideCursor(Qt::WaitCursor); out<<this->toPlainText(); QApplication::restoreOverrideCursor(); setCurrentFile(filename); return true; }like this just can get plaintext even if i use QDataStream but QTextStream.I want to get richtext form textedit include color and other info.What can i do? Thank for your help
-
If the content of the textedit are very simple (no resources) you can save the
toHtml()string and reload it usingsetHtml()if the document is more complex it's currently not available, see https://bugreports.qt.io/browse/QTBUG-9258 , you will have to implement it yourself