[Qt-interest] Slow QTreeWidget

Malyushytsky, Alex alex at wai.com
Wed Mar 25 19:58:39 CET 2009


You might want profile your code. The problem might be not in the tree.

I made a simple test application. Filled tree using your function (50 rows, 15 columns) and it is filled within 1 sec as it was.

Tested on Windows XP 64 bit, QT 4.4.3.

Regards,
         Alex


#include "treewidgettest.h"

treeWidgetTest::treeWidgetTest(QWidget *parent, Qt::WFlags flags)
        : QDialog(parent, flags)
{
        ui.setupUi(this);

    ui.treeWidget->setColumnCount(0);
    QStringList colTitles;
        int cols = 15;
        for (int col = 0; col<cols; col++)
        {
                colTitles << QString::number(col+1);
        }

        ui.treeWidget->setHeaderLabels(colTitles);

        connect ( ui.pushButtonFill, SIGNAL( clicked()), this, SLOT ( fillTreeWidget() ) );
}

treeWidgetTest::~treeWidgetTest()
{

}


void addResultRow(QTreeWidget *moduleRsltList, int rnr, int ct )
   {
   QList<QTreeWidgetItem *> lvitems=moduleRsltList->findItems
        (QString::number(rnr), Qt::MatchExactly,0);
   QTreeWidgetItem *lvitem=0;
   if (lvitems.count()>0)
     lvitem= lvitems[0];
   if (!lvitem)
     {
         double elaps_mins = 10.;
     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((i+1),'f',6));
     }
   }

void treeWidgetTest::fillTreeWidget()
{
        int rows = 50;
        int cols = 15;


        for (int row = 0; row < rows; row++ )
        addResultRow(ui.treeWidget,  row, cols );

}





-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Kenneth Beck
Sent: Wednesday, March 25, 2009 9:07 AM
To: R. Reucher; qt-interest at trolltech.com
Subject: Re: [Qt-interest] Slow QTreeWidget

R. Reucher wrote:
> On Wed March 25 2009 14:14:15 Kenneth Beck wrote:
>> setUpdatesEnabled(false) did not do much, except to delay the visual
>> update until the end. I have a progress bar that steps with each row
>> add, and the time between steps gets progressively slower as rows get
>> added, again as if it is looping back to somehow update all the previous
>> data with each call to setText.
> Are you sorting the entries while you insert them?
>
> I have QTreeWidget's with ~8000 entries (6 columns each) and they are filled
> within less than a second (using Qt 4.5 that is, with 4.4 this was
> perceptibly slower).
TreeView is MUCH MUCH faster! It would still be nice to know what I was
doing wrong on the TreeWidget -- there are other spots in my code that
have the same problem.
_______________________________________________
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