1
我有一個QTextEdit對象中有50行的表。 刪除50行1乘1,然後添加50行1乘1大約需要1-2秒。QTextEdit插入和刪除行非常慢。無論如何,讓它更快?
有什麼辦法可以加快這個操作。
我只需要看最後的結果。 (即我完成刪除後添加行)。
由於我知道什麼需要時間,我無法找到工作。
下面是一些簡單的代碼來測試它:
//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);
}
}
在開始操作之前,您可以嘗試隱藏(setHidden(true))textedit對象,並在結束時調用setShown(true)。 Qt小部件只在可見時重繪,否則update()信號將被忽略。也許這是因爲繪製... – ypnos 2012-03-30 23:06:21
使用'setUpdatesEnabled()'通常是一種更好的方式來完成ypnos描述的技巧。 – Chris 2012-03-30 23:14:01
剛剛測試過。 setHidden(true),setShown(true)沒有任何影響。設置setUpdatesEnabled(false),然後執行操作,然後執行setUpdatesEnable(true),也沒有任何影響。我想這與QTextEdit處理表格的方式有關。我不知道這是我的QT版本(它是4.7.4)。 – Anton 2012-03-30 23:24:31