QTextEdit插入和删除行非常慢.无论如何要让它更快?

Ant*_*ton 1 c++ performance qt qtextedit

我在QTextEdit对象中有一个包含50行的表.逐行删除50行,然后逐行添加50行需要大约1-2秒.

有没有办法加快这个操作.

我只需要看到最终的结果.(即在我完成删除然后添加行之后).

因为我知道究竟什么需要时间我找不到一个解决方法.

这是一些简单的代码来测试它:

//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);
    }
}
Run Code Online (Sandbox Code Playgroud)

ale*_*sdm 7

看起来如果你把代码放在调用textCursor.beginEditBlock()和之间textCursor.endEditBlock(),它被认为是一个单独的操作,并且更新是对你的500行测试的瞬间更新.