Unsolved QTextDocumentWriter removes transfers to tables when creating a document
-
Creating a document using QTextDocumentWriter. There is a table in the document. The tables use the hyphenation symbols cr, lf\n\r. QTextDocument displays the document correctly with hyphenations. But after QTextDocumentWriter, the hyphenations disappear.
sourceTextEdit = new QTextEdit(); editWidth=sourceTextEdit->width(); // ширина листа cursor = sourceTextEdit->textCursor(); // берем курсор cursor.movePosition(QTextCursor::Start); // устанавливаем курсор в начальное положение float textColumnFactor = 0.02; QVector<QTextLength> columnWidthConstraints; const QList<int> width { (int)(editWidth * textColumnFactor), (int)(editWidth * textColumnFactor) }; for(const auto & w : width) columnWidthConstraints.append(QTextLength(QTextLength::FixedLength, w)); cursor = sourceTextEdit->textCursor(); tableFormat.setColumnWidthConstraints(columnWidthConstraints); tableFormat.setAlignment(Qt::AlignCenter); tableFormat.setBorderStyle(QTextTableFormat::BorderStyle_Solid); tableFormat.setBorderBrush(QBrush(Qt::SolidPattern)); tableFormat.setBackground(Qt::white); tableFormat.setBorderCollapse(true); tableFormat.setCellPadding(0); tableFormat.setCellSpacing(0); tableFormat.setBorder(1); cellFormat.setTopPadding(1); cellFormat.setBottomPadding(1); orderTable = cursor.insertTable(3, 2, tableFormat); orderTable->setFormat(tableFormat); adjustCell(0, 0, textColumnFactor/20, Qt::AlignLeft, "Модель", "TimesNewRoman", 12, QFont::Normal); adjustCell(1, 0, textColumnFactor/20, Qt::AlignLeft, "Серийный номер", "TimesNewRoman", 12, QFont::Normal); adjustCell(2, 0, textColumnFactor/20, Qt::AlignLeft, "Протокол", "TimesNewRoman", 12, QFont::Normal); adjustCell(0, 1, textColumnFactor/20, Qt::AlignLeft, " \n\r ", "TimesNewRoman", 12, QFont::Normal); // хочу добавить перенос строки в это место чтобы в ячейки было две строки adjustCell(1, 1, textColumnFactor/20, Qt::AlignLeft, " \n\r ", "TimesNewRoman", 12, QFont::Normal); // хочу добавить перенос строки в это место чтобы в ячейки было две строки adjustCell(2, 1, textColumnFactor/20, Qt::AlignLeft, " \n\r ", "TimesNewRoman", 12, QFont::Normal); // хочу добавить перенос строки в это место чтобы в ячейки было две строки void Report::adjustCell(const int row, const int col, float columFactor, Qt::Alignment aalignment, QString text, QString fontName, qreal size, int fontWeight) { QFont font; font.setFamily(fontName); font.setPointSizeF(size); QTextCharFormat boldFormat; boldFormat.setFont(font); boldFormat.setFontWeight(fontWeight); auto cell = orderTable->cellAt(row, col); cellFormat.setLeftPadding(editWidth * columFactor); cell.setFormat(cellFormat); cell.firstCursorPosition().insertText(text, boldFormat); cursor=cell.firstCursorPosition(); cellAlign.setAlignment(aalignment); cursor.setBlockFormat(cellAlign); } /* создание документа */ QPrinter printer(QPrinter::ScreenResolution); printer.setPaperSize(QPrinter::A4); QSizeF paperSize; paperSize.setWidth(printer.width()); paperSize.setHeight(printer.height()); textDocument = sourceTextEdit->document(); // создаем документ textDocument->setPageSize(paperSize); writer.setFormat("odf"); writer.setFileName("/media/usb0/report.odt"); writer.write(textDocument);