[Qt-interest] Slow QTreeWidget

Malyushytsky, Alex alex at wai.com
Wed Mar 25 06:53:24 CET 2009


findItems is definetely slower with each extra item added.
But I would say such initialization may be considered "big visual change"
and major time is spend on visualization of each set - basically as many time as number of rows you have,  multiplied by the number of columns
(lvitem->setText(i+1,QString::number(data[i-1],'f',6));)
Even if QTreeWidget was trying to buffer changes itself (I am too lazy to read sources right now), it might not work that well in all situations.
And the best way don't count on it anyway.

Try  to use setUpdatesEnabled, as in QT example:

 setUpdatesEnabled(false);
 bigVisualChanges(); // loop with your addResultRow call
 setUpdatesEnabled(true);


Hope this helps,
  Alex Malyushytsky

-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Kenneth Beck
Sent: Tuesday, March 24, 2009 8:08 PM
To: qt-interest at trolltech.com
Subject: [Qt-interest] Slow QTreeWidget

Can someone tell me why my performance is so slow with this code? I am
filling a tree widget that has about 40+ columns, but only 14 rows. As
the table is filled with all 14 rows initially, the first row is added
quickly, but each subsequent row appears more and more slowly, as if the
code is updating previous rows for each new row. Here is the code for
adding a row:

void
ModMaxTestDlg::addResultRow(double elaps_mins, int rnr, int ct, double
*data)
   {
   QList<QTreeWidgetItem *> lvitems=moduleRsltList->findItems
        (QString::number(rnr), Qt::MatchExactly,0);
   QTreeWidgetItem *lvitem=0;
   if (lvitems.count()>0)
     lvitem= lvitems[0];
   if (!lvitem)
     {
     lvitem= new QTreeWidgetItem(moduleRsltList);
     lvitem->setData(0,Qt::DisplayRole,QString::number(rnr));
     lvitem->setData(1,Qt::DisplayRole,
        QString::number(elaps_mins,'f',2));
     }
   if (ct && (lvitem!=0))
     {
     int i;
     for (i=1;i<=ct;i++)
       lvitem->setText(i+1,QString::number(data[i-1],'f',6));
     }
   }

The addResultRow() gets called in a simple for-loop. I know the time
constraint is here, in the last for loop that calls lvitem->setText ct
times.

Qt 4.5.0, Windows XP, using Visual C++ 2003.
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest


---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."

"Please consider our environment before printing this email."




More information about the Qt-interest-old mailing list