View Full Version : How to handle amount of text blocks?

29th January 2014, 14:04
Hi Guys,

I would like to know if there is one solution to handle thousands of text blocks and set invisible to them at one time?

It is very slow if the program set visible as false/true as block by block.

Thank you in advance :)

29th January 2014, 22:09
Do you mean QTextBlocks in a QTextDocument?

30th January 2014, 01:16
Yes, Chris.

I am not quite sure if we can control the attributes of text in the block with paint or draw event as it should be faster rather than setting the visible to true/false for thousands of blocks.


Or is there any frame to warp the text block and we can simply add blocks into a container and set visibility to the container at one time?

30th January 2014, 01:41
Some options to explore to improve performance.

If the document is visible then each time you change the visibility of a block the widget will get an update event. So, try calling textEdit->setUpdatesEnabled(false), process the visibility of blocks, then textEdit->setUpdatesEnabled(true).

I am not sure if QTextDocument tracks block visibility with undo events, so you could try also try wrapping the changes with document->setUndoRedoEnabled().

30th January 2014, 02:15
Thanks Chris.

I will have a try and let you know then :)

30th January 2014, 08:20
Unfortunately, it does not work by seting setUpdateEnabled to true/false and it is still slow. the change history does not save the action for visibility setting.

4th February 2014, 14:26
I plan to use QTimer and set interval as 40 min sec then it should be resolved.

4th February 2014, 20:19
What does a timer have to do with the topic of this thread?

4th February 2014, 22:24
Hi Chris,

Because of there are 10k text blocks need to be set visibility as show/hidden, I would like to allow the program to process 1000 blocks every 40 min secs with QTimer until all of them are finalized, then it should be resolved as I expected but I have not modified yet.

I tried to use QTextLayout, QTextLine, QPlainTextDocumentLayout and QTextFrame, they are not working for this case.

Please correct me if I am wrong :)