<?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[Handle QTextBlock with multples lines (Html) to display line numbers]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I've created a text editor quite similar to this one (Qt 4.8):<br />
<a href="https://doc.qt.io/qt-5/qtwidgets-widgets-codeeditor-example.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/qtwidgets-widgets-codeeditor-example.html</a></p>
<p dir="auto">Primarily it consists of a QPlainTextEdit and a line number bar on the left. The QPlainTextEdit might also<br />
contain text formatted as HTML (added with appendHthml() function).</p>
<p dir="auto">If the QPlainTextEdit contains plain text, the line numbers are correct and each text line is in its own QTextBlock.<br />
Therefore the function lineNumberAreaPaintEvent() (see example above) works correclty.<br />
But once HTML formatted text is added, QPlainTextEdit consists of a single QTextBlock that contains all text.<br />
Therefore the function lineNumberAreaPaintEvent() does not work correctly anymore.</p>
<p dir="auto">The following code of the function lineNumberAreaPaintEvent()</p>
<pre><code>while (block.isValid() &amp;&amp; top &lt;= event-&gt;rect().bottom()) {
        if (block.isVisible() &amp;&amp; bottom &gt;= event-&gt;rect().top()) {
//....
        }

        block = block.next();
        top = bottom;
        bottom = top + qRound(blockBoundingRect(block).height());
        ++blockNumber;
}
</code></pre>
<p dir="auto">is very important to prevent unnecessary draw events that will otherwise hurt scroll performance when working with very large documents. Is there maybe a way to have every line of the HTML formatted text in its own QTextBlock so that the function will work again? Or can you find out which lines of a QTextBlock are currently displyed to paint only the necessary line numbers?</p>
<p dir="auto">Thank you very much<br />
skmCry</p>
]]></description><link>https://forum.qt.io/topic/117061/handle-qtextblock-with-multples-lines-html-to-display-line-numbers</link><generator>RSS for Node</generator><lastBuildDate>Thu, 30 Jul 2026 07:15:17 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/117061.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 15 Jul 2020 21:11:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Handle QTextBlock with multples lines (Html) to display line numbers on Fri, 31 Jul 2020 14:53:15 GMT]]></title><description><![CDATA[<p dir="auto">For everyone who is interested; The above example/text editor works correctly if the Html text is formatted correclty. Each line must be in its own paragraph (&lt;p&gt; tag), then Qt is able to create invidiual QTextBlock objects for each line. &lt;br&gt; does not work.</p>
]]></description><link>https://forum.qt.io/post/609925</link><guid isPermaLink="true">https://forum.qt.io/post/609925</guid><dc:creator><![CDATA[skmCry]]></dc:creator><pubDate>Fri, 31 Jul 2020 14:53:15 GMT</pubDate></item></channel></rss>