[Interest] QTextDocument/QTextCursor: inserting, editing blocks

Vojtěch Král vojtech at kral.hk
Wed Sep 11 21:39:44 CEST 2013



Ok, great, thanks for the clarification. 

I've decided to trust that QTextDocument is well optimised ;-) 

(And having done some rough test I can say it seems it indeed is) 

Best Regards, 

Vojtech Kral 

On 2013-09-11 19:20, Gopalakrishna Bhat wrote: 

> 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 [1]
> 
> Regards, 
> Gopalakrishna
> -- 
> My blog http://gkbhat.blogspot.com [2]


Links:
------
[1] http://lists.qt-project.org/mailman/listinfo/interest
[2] http://gkbhat.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130911/3f058b22/attachment.html>


More information about the Interest mailing list