Anton
Anton

Reputation: 1211

QTextEdit inserting and removing rows is very slow. Anyway to make it faster?

I have a table with 50 rows in a QTextEdit object. Removing 50 rows 1 by 1, then adding 50 rows 1 by 1 takes around 1-2 seconds.

Is there any way to speed up this operation.

I only need to see the final result. (ie after i have finished removing then adding rows).

Since i down know exactly what takes time i can not find a work around.

Here is some simple code to test it out:

//ui->textEdit is the text edit control
//This will insert 500 rows then remove 499 rows.

QTextCursor textCursor = ui->textEdit->textCursor();
textCursor.setPosition(1);
if(textCursor.currentTable() !=0)
{
    for(int i =0;i<500;i++)
    {
        textCursor.currentTable()->insertRows(1,1);
    }
    for(int i =0;i<499;i++)
    {
        textCursor.currentTable()->removeRows(1,1);
    }
}

Upvotes: 1

Views: 1941

Answers (1)

alexisdm
alexisdm

Reputation: 29886

It seems that if you put your code between calls to textCursor.beginEditBlock() and textCursor.endEditBlock(), it is considered as a single operation, and the update is instantaneous for your 500 row test.

Upvotes: 7

Related Questions