I write the data to the file (world) in general, everything is fine. But I need to write data to a file with different fonts and the size of the letters. For example, one line "Report" in size 16 and oral font, and the other line "obtained results" in size 12 and Calibri font.

I was advised to dig in the direction of QFont , but there I only managed to change the characteristics of the widgets, and not the text to send to the file.

 //файл вывода (хотелось бы изменить шрифт и размеры строкам strObrabotka0 , strObrabotka1) QString strObrabotka0; QString strObrabotka; QString strObrabotka1; //попытка дать строке другой шрифт QFont Font("Times", 14, QFont::Bold); QString text = tr( "GAME OVER" ); //----------------------------------------------- strObrabotka0.append(QString("%1 %2 %3").arg("Время запуска программы ").arg(strObrabotka1).arg("\n")); strObrabotka.append(QString("%1 %2").arg(" -------------------------------------------------------- ").arg("\n")); strObrabotka.append(QString("%1 %2 %3 %4").arg("Коэффициент усиления ").arg(obm->stor->per_koef_usilen_2).arg("Дб").arg("\n")); strObrabotka.append(QString("%1 %2 %3 %4").arg("Длительность излучаемого сигнала ").arg(obm->stor->per_dlina_izlych_signala).arg("Мс").arg("\n")); strObrabotka.append(QString("%1 %2 %3 %4").arg("Период следования излучаемых импульсов ").arg(obm->stor->per_vrema_izlych_impuls).arg("С").arg("\n")); strObrabotka.append(QString("%1 %2 %3 %4").arg("Рабочая частота ").arg(obm->stor->per_rabChastota_2).arg("кГц").arg("\n")); strObrabotka1.append(QString("%1 %2").arg("Обработанные данные лежат в документе win.xls ").arg("\n")); // очиста файла перед работой QFile file2("wivod.txt"); file2.open(QIODevice::WriteOnly | QIODevice::Text); // если сюда ввести (фаил закрыть) то но просто очистит документ file2.close(); file2.open(QIODevice::Append | QIODevice::Text); QTextStream out(&file2); out.setCodec("UTF-8"); out << strObrabotka0; out << strObrabotka; out << strObrabotka1; file2.close(); 

In general, I did as you and I advised

 QTextEdit* ptxt = new QTextEdit("<em>текст</em> <strong>текст</strong> <b>текст</b><i>а этот - ещё и курсивным</i>"); QTextDocumentWriter writer; writer.setFormat("odf"); writer.setFileName("wivodi.odf"); // writer.setCodec("UTF-8"); writer.write(ptxt->document()); 

But basically he writes all kinds of cracks. How to solve this problem ?

    2 answers 2

    Plain text files do not support formatting. You can output formatted text in HTML format, in addition, Qt also supports ODF format .

    In general, this is the answer to my question, but only, I did not solve one problem with this font, for some reason it does not accept the 0_o command.

     QString text = QObject::trUtf8("<p align=\"center\"> <font size=\"16\">Размер шрифта = 16</font></p> <br> <font size=\"25\" color=\"red\" face=\"Arial\"> <strong><em>Отчет</em></strong> </font> <br> <strong>текст</strong> <br> <b>текст</b><i>а этот - ещё и курсивным</i> "); QTextDocumentWriter writer; writer.setFormat("odf"); writer.setFileName("wivodi.odf"); QTextEdit *strin = new QTextEdit(text); writer.write(strin->document()); 

    Only he writes it down once and if he writes it again, he “clears” the file and writes it back to him, I could not “fill up” the file, but I didn’t make a big line on append swearing during the build