[Interest] QTextDocument/QTextCursor: inserting, editing blocks

Gopalakrishna Bhat gopalakbhat at gmail.com
Wed Sep 11 19:20:27 CEST 2013


On Wed, Sep 11, 2013 at 9:43 PM, Vojtěch Král <vojtech at kral.hk> wrote:

> Hi,
> I don't understand how to edit text blocks in QTextDocument using
> QTextCursor.
> So far I've been inserting text using QTextCursor::insertText() and it
> worked fine,
> however, I later noticed that each call to QTextCursor::insertText()
> creates a new QTextBlock within the document.
>
> Is it possible to somehow append text to an existing block instead of
> creating a new one?
> My concern is that this might incur a lot of overhead both in terms of
> cpu time and memory, especially once the document contains a lot of
> text.
>
> CPU and memory should not be a big issue. There are bigger applications
out there that opens complexly formatted documents MBs in size using
QTextBlocks.


> In this regard I'm also wondering what is the purpose of void
> QTextCursor::insertBlock().
> I can't seem to find a way how this group of functions would ever be
> useful, but I assume there is a reason they are provided.
>
> QTextCursor::insertText inserts a new QTextBlock with the current
character format.
QTextCursor::insertBlock allows you to create a new text block set a format
to it and then insert

Something on the lines of

QTextBlockFormat blockFormat;

QTextCharFormat textCharFormat;
textCharFormat.setFontPointSize(11);

textCharFormat.setFontWeight(QFont::Normal);

cursor.insertBlock(blockFormat, textCharFormat);


If it is of any relevance I'm using QTextDocument to display output of a
> console application, including support color of formatting/coloring
> escape sequences etc., which works fine, apart from the large block
> count problem.
>
> Thanks for any advice.
> VK
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>

Regards,
Gopalakrishna
-- 
My blog http://gkbhat.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130911/6a342079/attachment.html>


More information about the Interest mailing list