<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QTextDocumentWriter does not create a document with nested tables]]></title><description><![CDATA[<p dir="auto">I want to get a format file at the output .odt. The file should contain tables, text, and pictures. I started with tables.</p>
<p dir="auto">Made a test code:</p>
<pre><code>ui-&gt;textEdit-&gt;setHtml(QString(
                              "&lt;style&gt;"
                               //для всех таблиц
                              //"table {width:100%;background: black;border: 2px solid white;}"
                              //"th { padding: 3px; color:white; background-color: black;border: 1px solid white;border-collapse:collapse;}"
                              //"tr { padding: 3px;color:white; background-color: black;border: 1px solid white;border-collapse:collapse;}"
                              //"td { padding: 3px;color:white; background-color: black;border: 1px solid white;border-collapse:collapse;}"

                               //класс на каждую ячейку
                               ".outer {background-color: cyan;}"
                               ".inner {padding: 1px; background-color: black;}"
                               ".cell_A { padding: 3px; color:black; background-color: white;}"
                               ".cell_B { padding: 3px; color:white; background-color: gray;}"
                              "&lt;/style&gt; "

                            "&lt;H1&gt;&lt;CENTER&gt;"
                            "&lt;font color='black'&gt;&lt;b&gt;ПРОТОКОЛ ИСПЫТАНИЯ АККУМУЛЯТОРА №1&lt;/b&gt;"
                            "&lt;/CENTER&gt;&lt;/H1&gt;"

                            " &lt;CENTER&gt; "
                            " &lt;TABLE class='outer'&gt;"
                            " &lt;tr&gt;"

                            " &lt;td&gt;"
                            " &lt;TABLE class='inner'&gt;"
                            " &lt;tr class='cell_A'&gt;&lt;td class='cell_A'&gt;Емкость при разряде&lt;/td&gt;&lt;td class='cell_A'&gt;43&lt;/td&gt;&lt;/tr&gt;"
                            " &lt;tr class='cell_A'&gt;&lt;td class='cell_A'&gt;Остаточная емкость&lt;/td&gt;&lt;td class='cell_A'&gt;86&lt;/td&gt;&lt;/tr&gt;"
                            " &lt;tr class='cell_A'&gt;&lt;td class='cell_A'&gt;Энергия полная&lt;/td&gt;&lt;td class='cell_A'&gt;556&lt;/td&gt;&lt;/tr&gt;"
                            " &lt;tr class='cell_A'&gt;&lt;td class='cell_A'&gt;Емкость при заряде&lt;/td&gt;&lt;td class='cell_A'&gt;52&lt;/td&gt;&lt;/tr&gt;"
                            " &lt;tr class='cell_A'&gt;&lt;td class='cell_A'&gt;КПД заряда&lt;/td&gt;&lt;td class='cell_A'&gt;83&lt;/td&gt;&lt;/tr&gt;"
                            " &lt;/TABLE&gt; "
                            " &lt;/td&gt;"

                            " &lt;td&gt;"
                            " &lt;TABLE class='inner'&gt;"
                            " &lt;tr class='cell_B'&gt;&lt;td class='cell_B'&gt;ЭПС 90% разряд&lt;/td&gt;&lt;td class='cell_B'&gt;11&lt;/td&gt;&lt;/tr&gt;"
                            " &lt;tr class='cell_B'&gt;&lt;td class='cell_B'&gt;ЭПС 50% разряд&lt;/td&gt;&lt;td class='cell_B'&gt;12&lt;/td&gt;&lt;/tr&gt;"
                            " &lt;tr class='cell_B'&gt;&lt;td class='cell_B'&gt;ЭПС 90% заряд&lt;/td&gt;&lt;td class='cell_B'&gt;13&lt;/td&gt;&lt;/tr&gt;"
                            " &lt;tr class='cell_B'&gt;&lt;td class='cell_B'&gt;ЭПС 50% заряд&lt;/td&gt;&lt;td class='cell_B'&gt;11&lt;/td&gt;&lt;/tr&gt;"
                            " &lt;tr class='cell_B'&gt;&lt;td class='cell_B'&gt;&lt;/td&gt;&lt;td class='cell_B'&gt;4&lt;/td&gt;&lt;/tr&gt;"
                            " &lt;/TABLE&gt; "
                            " &lt;/td&gt;"

                            " &lt;/tr&gt;"
                            " &lt;/TABLE&gt; "
                            " &lt;/CENTER&gt;"
                               ));

     textDocument =  ui-&gt;textEdit-&gt;document();
     QTextDocumentWriter writer;
     writer.setFormat("odf");
     writer.setFileName("/media/usb0/report.odt");
     writer.write(textDocument);
</code></pre>
<p dir="auto">There is no table in the output file. There is a table in QTextEdit, checked by output to the screen.<br />
<img src="https://ddgobkiprc33d.cloudfront.net/aa9a5f82-5cf7-4990-8184-e1b757bc24e3.png" alt="что получил.png" class=" img-fluid img-markdown" /> !<br />
<img src="https://ddgobkiprc33d.cloudfront.net/0fd0415e-235b-4868-927a-d7ea7c827b39.jpg" alt="20230120_165058.jpg" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/topic/142350/qtextdocumentwriter-does-not-create-a-document-with-nested-tables</link><generator>RSS for Node</generator><lastBuildDate>Sun, 02 Aug 2026 12:56:23 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/142350.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 21 Jan 2023 14:09:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QTextDocumentWriter does not create a document with nested tables on Sat, 21 Jan 2023 15:34:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alexeygolubev92">@<bdi>AlexeyGolubev92</bdi></a></p>
<p dir="auto">Hi, what Qt version do you use?<br />
I fear, you cant use <code>&lt;style&gt;</code> tags in <code>QTextEdit</code> / RichText, since in Qt5 LTS and even in the latest Qt6 it doesn't support it. Only the listed tags are usable. That's why your style content is skipped and you only see the empty <code>&lt;tr&gt;</code> table-row.</p>
<ul>
<li><a href="https://doc.qt.io/qt-5/richtext-html-subset.html#supported-tags" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/richtext-html-subset.html#supported-tags</a></li>
<li><a href="https://doc.qt.io/qt-6/richtext-html-subset.html#supported-tags" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-6/richtext-html-subset.html#supported-tags</a></li>
</ul>
<p dir="auto">Edit:<br />
But maybe it's an issue when writing it to ODF.<br />
What do you get, when you print your <code>QTextDocument</code> with</p>
<pre><code>textDocument =  ui-&gt;textEdit-&gt;document();
textDocument.toHtml()
</code></pre>
<p dir="auto"><a href="https://doc.qt.io/qt-6/qtextdocument.html#toHtml" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-6/qtextdocument.html#toHtml</a></p>
]]></description><link>https://forum.qt.io/post/744691</link><guid isPermaLink="true">https://forum.qt.io/post/744691</guid><dc:creator><![CDATA[Pl45m4]]></dc:creator><pubDate>Sat, 21 Jan 2023 15:34:29 GMT</pubDate></item></channel></rss>