<?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[Designate QTextBlock as &quot;Heading 1&quot;]]></title><description><![CDATA[<p dir="auto">I build a QTextDocument by code using QTextCursor, and then export it to file in open document format. So far, so good, I can see my text and formats (font size, etc.).</p>
<p dir="auto">However, I'd like to designate a text block as "Heading 1", "Heading 2", etc., so that the user can later on easily create a table of contents from my exported document, in the word processing program of their choice.</p>
<p dir="auto">Is that possible, and if so, how?</p>
]]></description><link>https://forum.qt.io/topic/82433/designate-qtextblock-as-heading-1</link><generator>RSS for Node</generator><lastBuildDate>Sun, 19 Apr 2026 12:58:39 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/82433.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 16 Aug 2017 10:01:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Designate QTextBlock as &quot;Heading 1&quot; on Wed, 16 Aug 2017 15:03:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/asperamanca">@<bdi>Asperamanca</bdi></a><br />
<code>QTextBlock</code> derives <code>QTextFormat</code>. QTextFormat can store user properties (see <a href="http://doc.qt.io/qt-5/qtextformat.html#setProperty" target="_blank" rel="noopener noreferrer nofollow ugc">QTextFormat::setProperty()</a>)<br />
You just need to define an enum with your custom property ids for example:</p>
<pre><code>enum PropertyId {
     Heading1PropertyId = QTextFormat::UserProperty+1000
};
...
textBlock.setProperty(Heading1PropertyId, QVariant::fromValue&lt;bool&gt;(true));
textBlock.boolProperty(Heading1PropertyId); // convenience getter
</code></pre>
]]></description><link>https://forum.qt.io/post/410728</link><guid isPermaLink="true">https://forum.qt.io/post/410728</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Wed, 16 Aug 2017 15:03:07 GMT</pubDate></item><item><title><![CDATA[Reply to Designate QTextBlock as &quot;Heading 1&quot; on Wed, 16 Aug 2017 10:25:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/asperamanca">@<bdi>Asperamanca</bdi></a> It is just zero-based index count of all the blocks in the QTextDocument.</p>
]]></description><link>https://forum.qt.io/post/410664</link><guid isPermaLink="true">https://forum.qt.io/post/410664</guid><dc:creator><![CDATA[artwaw]]></dc:creator><pubDate>Wed, 16 Aug 2017 10:25:35 GMT</pubDate></item><item><title><![CDATA[Reply to Designate QTextBlock as &quot;Heading 1&quot; on Wed, 16 Aug 2017 10:19:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/artwaw">@<bdi>artwaw</bdi></a><br />
Docs on blockNumber: "Note that this function only makes sense in documents without complex objects such as tables or frames."<br />
Also, it doesn't seem to have a set method, so I guess the number is automatically determined in some way.</p>
]]></description><link>https://forum.qt.io/post/410662</link><guid isPermaLink="true">https://forum.qt.io/post/410662</guid><dc:creator><![CDATA[Asperamanca]]></dc:creator><pubDate>Wed, 16 Aug 2017 10:19:00 GMT</pubDate></item><item><title><![CDATA[Reply to Designate QTextBlock as &quot;Heading 1&quot; on Wed, 16 Aug 2017 10:15:14 GMT]]></title><description><![CDATA[<p dir="auto">Hi,<br />
as far as I know QTextBlock has its own int number so it would be possible to add a string of your own and then <a href="http://doc.qt.io/qt-4.8/qtextblock.html#blockNumber" target="_blank" rel="noopener noreferrer nofollow ugc">QTextBlock::blockNumber()</a>.<br />
However there is no QString identifier in the QTextBlock itself that I know of.</p>
]]></description><link>https://forum.qt.io/post/410660</link><guid isPermaLink="true">https://forum.qt.io/post/410660</guid><dc:creator><![CDATA[artwaw]]></dc:creator><pubDate>Wed, 16 Aug 2017 10:15:14 GMT</pubDate></item></channel></rss>